Switch from catppuccin to ayu mirage for various tools, switch from p10k to starship, self made tmux and sway statusbar update

This commit is contained in:
Martin Larsson 2025-01-09 17:22:50 +01:00
parent 886818cd1f
commit 93e41aef46
11 changed files with 412 additions and 1874 deletions

View file

@ -0,0 +1,174 @@
#!/bin/bash
#############################
# Icons for Linux Battery
#############################
# This icon is used for macOS (no dynamic levels).
MAC_BATTERY_ICON=""
# Charging icon (positive power_now)
BATTERY_CHARGING_ICON="󰂄"
# Discharging icons based on capacity
BATTERY_FULL_ICON="" # 80%100%
BATTERY_3QTR_ICON="" # 60%79%
BATTERY_HALF_ICON="" # 40%59%
BATTERY_QTR_ICON="" # 20%39%
BATTERY_EMPTY_ICON="" # 0%19%
#############################
# macOS Battery
#############################
get_battery_info_mac() {
# pmset is the standard battery command on macOS
if ! command -v pmset &>/dev/null; then
return 1
fi
capacity=$(pmset -g batt | grep -o "\d\+%" | head -n1 | tr -d '%')
if [[ -n "$capacity" ]]; then
# Just show generic icon + capacity on mac
echo "$MAC_BATTERY_ICON $capacity%"
return 0
fi
return 1
}
#############################
# Linux Battery
#############################
get_battery_info_linux() {
local path="$1"
# Early return if path is not valid
if [ -z "$path" ]; then
return 1
fi
# capacity
if [ -r "$path/capacity" ]; then
capacity=$(cat "$path/capacity")
else
capacity=""
fi
# power_now
power_now=""
if [ -r "$path/power_now" ]; then
power_now=$(cat "$path/power_now")
elif [ -r "$path/current_now" ] && [ -r "$path/voltage_now" ]; then
# Some systems use current_now and voltage_now
current_now=$(cat "$path/current_now")
voltage_now=$(cat "$path/voltage_now")
if [[ -n "$current_now" && -n "$voltage_now" ]]; then
# (current_now * voltage_now) / 1e6 => watts
power_now=$(echo "scale=2; ($current_now * $voltage_now) / 1000000" | bc)
fi
fi
# If we got capacity at all
if [[ -n "$capacity" ]]; then
# Figure out numeric or empty power
if [[ -n "$power_now" ]]; then
# Determine if power_now is micro- or milliwatts
abs_power_now=${power_now#-} # remove leading '-' if present
if (( abs_power_now > 10000 )); then
# microwatts -> W
power_consumption_watts=$(echo "scale=2; $power_now / 1000000" | bc)
else
# milliwatts -> W
power_consumption_watts=$(echo "scale=2; $power_now / 1000" | bc)
fi
fi
# Decide if charging or discharging
# (If power_now > 0 => charging, < 0 => discharging)
local battery_icon
if [[ -n "$power_now" ]]; then
# numeric check: is it > 0 or < 0?
float_power=$(echo "$power_now" | sed 's/^+//; s/,/./')
# strip any trailing newline, just in case
if (( $(echo "$float_power > 0" | bc -l) )); then
# CHARGING
battery_icon="$BATTERY_CHARGING_ICON"
else
# DISCHARGING - pick icon by capacity
battery_icon=$(pick_battery_icon "$capacity")
fi
else
# Unknown or no power_now => treat as discharging
battery_icon=$(pick_battery_icon "$capacity")
fi
# Build the final string
if [[ -n "$power_consumption_watts" ]]; then
echo "$battery_icon $capacity% (${power_consumption_watts} W)"
else
echo "$battery_icon $capacity%"
fi
return 0
fi
return 1
}
#############################
# Helper to pick icon by capacity
#############################
pick_battery_icon() {
local cap="$1"
# convert to integer
if [ "$cap" -ge 80 ]; then
echo "$BATTERY_FULL_ICON"
elif [ "$cap" -ge 60 ]; then
echo "$BATTERY_3QTR_ICON"
elif [ "$cap" -ge 40 ]; then
echo "$BATTERY_HALF_ICON"
elif [ "$cap" -ge 20 ]; then
echo "$BATTERY_QTR_ICON"
else
echo "$BATTERY_EMPTY_ICON"
fi
}
#############################
# Gather battery info
#############################
get_battery_info_linux_main() {
battery_paths=(
"/sys/class/power_supply/macsmc-battery" # Asahi (M1) Fedora Remix
"/sys/class/power_supply/BAT0" # Standard Linux
"/sys/class/power_supply/BAT1" # Common secondary
)
for path in "${battery_paths[@]}"; do
if [ -d "$path" ]; then
battery_info=$(get_battery_info_linux "$path")
if [ $? -eq 0 ]; then
echo "$battery_info"
return
fi
fi
done
}
#############################
# Main logic
#############################
OS="$(uname)"
case "$OS" in
Darwin)
battery=$(get_battery_info_mac)
;;
Linux)
battery=$(get_battery_info_linux_main)
;;
*)
# Unsupported OS, no output
battery=""
;;
esac
echo "$battery"

View file

@ -0,0 +1,4 @@
# Get editor completions based on the config schema
"$schema" = 'https://starship.rs/config-schema.json'
add_newline = true

View file

@ -0,0 +1,44 @@
#!/bin/zsh
# program blacklist
# program=$(
# ps -o comm= -t "$(tmux display-message -p '#{pane_tty}')" 2>/dev/null \
# | grep -v '^ps$' \
# | grep -v 'tmux-rename-window' \
# | grep -v 'tail' \
# | grep -v 'head' \
# | grep -v 'grep' \
# | grep -v 'find' \
# | grep -v 'rg' \
# | grep -v 'jq' \
# | grep -v 'perl' \
# | grep -v 'fzf' \
# | grep -v 'bat' \
# | grep -v 'cat' \
# | grep -v 'tldr' \
# | grep -v 'man' \
# | tail -n1
# )
# Fallback if empty:
# [[ -z "$program" ]] && program="zsh"
# Get the current working directory
cwd=$(tmux display-message -p '#{pane_current_path}')
# If the program is zsh (or bash, etc.), show dir name
# if [[ "$program" == "zsh" || "$program" == "bash" || "$program" == "sh" ]]; then
[[ "$cwd" == "$HOME" ]] && dirname="~" || dirname=$(basename "$cwd")
name="$dirname/"
# else
# name="$program"
# fi
# Now do your truncation/padding
MAX_WIDTH=15
if [ "${#name}" -gt "$MAX_WIDTH" ]; then
truncated="${name:0:$(($MAX_WIDTH-2))}…/"
echo "$truncated"
else
echo "$name"
fi

View file

@ -0,0 +1,15 @@
format_for_tmux() {
fg="#1F2430"
bg="#73D0FF"
text_col="#CCCAC2"
echo $1 | awk -v bg="$bg" -v fg="$fg" -v text_col="$text_col" '{printf("#[default]#[fg="bg"]#[default]#[bg="bg", fg="fg"]%s#[default]#[fg="bg"]#[default]#[fg="text_col"] %s", substr($0, 1, 1), substr($0, 2))}'
}
battery_result=$($HOME/.config/confutils/get-battery.sh)
space=" "
session=$(format_for_tmux "#S")
battery=$(format_for_tmux "$battery_result")
calendar=$(format_for_tmux "$(date +"%a %b %d")")
echo $session$space$battery$space$calendar

File diff suppressed because it is too large Load diff

View file

@ -81,15 +81,6 @@ set-option -ga terminal-overrides ',*:Tc'
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm'
set -as terminal-overrides ',*:Setulc=\E[58::2::::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'
# Set the default terminal to support 256 colors
# set -g default-terminal "xterm-ghostty"
# Ensure tmux uses true color
# set-option -ga terminal-features 'xterm-256color:RGB'
# set-option -ga terminal-overrides ',xterm-256color:Tc'
# set-option -ga terminal-features 'xterm-ghostty:RGB'
# set-option -ga terminal-overrides ',xterm-ghostty:Tc'
# Make sure that the index of windows and panes starts at 1
set -g base-index 1
set -g pane-base-index 1
@ -97,15 +88,44 @@ set -g renumber-windows on
set -g mode-keys vi
set -g history-limit 10000
set-option -g status-position top
set -g @catppuccin_flavour "macchiato"
set -g @catppuccin_status_background "#1e2030"
set -g @plugin "catppuccin/tmux"
# Address vim mode switching delay (http://superuser.com/a/252717/65504)
set -s escape-time 0
set -g @plugin "tmux-plugins/tmux-sensible"
# Increase scrollback buffer size from 2000 to 50000 lines
set -g history-limit 50000
# Increase tmux messages display duration from 750ms to 4s
set -g display-time 2500
# Refresh 'status-left' and 'status-right' more often, from every 15s to 5s
set -g status-interval 2
# Focus events enabled for terminals that support them
set -g focus-events on
# Super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on
# Set the left status: Tabs (window names)
set -g status-left ""
setw -g automatic-rename off
set-hook -g after-new-window "run-shell '~/.config/tmux/tmux-rename-window.sh | xargs tmux rename-window'"
set-hook -g pane-focus-in "run-shell '~/.config/tmux/tmux-rename-window.sh | xargs tmux rename-window'"
setw -g window-status-format "#[bg=#171B24,fg=#CCCAC2] #[bold]#I #[default] #[fg=#73D0FF]#W #[default]"
setw -g window-status-current-format "#[bg=#757B84,fg=#EFEDE7] #[bold]#I #[default] #[fg=#FFAD66]#W #[default]"
# Set the right status: Battery, date and time, session name
set -g status-right "#($HOME/.config/tmux/tmux-status-right.sh) | #S#[default]"
set -g status-bg "#171B24"
set -g status-style bold
# set -g @catppuccin_flavour "macchiato"
# set -g @catppuccin_status_background "#1e2030"
# set -g @plugin "catppuccin/tmux"
set -g @plugin "tmux-plugins/tpm"
run "~/dev/git/tpm/tpm"

View file

@ -1,74 +0,0 @@
# Catppuccin Macchiato Theme (for zsh-syntax-highlighting)
#
# Paste this files contents inside your ~/.zshrc before you activate zsh-syntax-highlighting
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main cursor)
typeset -gA ZSH_HIGHLIGHT_STYLES
# Main highlighter styling: https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md
#
## General
### Diffs
### Markup
## Classes
## Comments
ZSH_HIGHLIGHT_STYLES[comment]='fg=#5b6078'
## Constants
## Entitites
## Functions/methods
ZSH_HIGHLIGHT_STYLES[alias]='fg=#a6da95'
ZSH_HIGHLIGHT_STYLES[suffix-alias]='fg=#a6da95'
ZSH_HIGHLIGHT_STYLES[global-alias]='fg=#a6da95'
ZSH_HIGHLIGHT_STYLES[function]='fg=#a6da95'
ZSH_HIGHLIGHT_STYLES[command]='fg=#a6da95'
ZSH_HIGHLIGHT_STYLES[precommand]='fg=#a6da95,italic'
ZSH_HIGHLIGHT_STYLES[autodirectory]='fg=#f5a97f,italic'
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=#f5a97f'
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=#f5a97f'
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]='fg=#c6a0f6'
## Keywords
## Built ins
ZSH_HIGHLIGHT_STYLES[builtin]='fg=#a6da95'
ZSH_HIGHLIGHT_STYLES[reserved-word]='fg=#a6da95'
ZSH_HIGHLIGHT_STYLES[hashed-command]='fg=#a6da95'
## Punctuation
ZSH_HIGHLIGHT_STYLES[commandseparator]='fg=#ed8796'
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter-unquoted]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]='fg=#ed8796'
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]='fg=#ed8796'
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]='fg=#ed8796'
## Serializable / Configuration Languages
## Storage
## Strings
ZSH_HIGHLIGHT_STYLES[command-substitution-quoted]='fg=#eed49f'
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter-quoted]='fg=#eed49f'
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=#eed49f'
ZSH_HIGHLIGHT_STYLES[single-quoted-argument-unclosed]='fg=#ee99a0'
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=#eed49f'
ZSH_HIGHLIGHT_STYLES[double-quoted-argument-unclosed]='fg=#ee99a0'
ZSH_HIGHLIGHT_STYLES[rc-quote]='fg=#eed49f'
## Variables
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument-unclosed]='fg=#ee99a0'
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[assign]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[named-fd]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[numeric-fd]='fg=#cad3f5'
## No category relevant in spec
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=#ee99a0'
ZSH_HIGHLIGHT_STYLES[path]='fg=#cad3f5,underline'
ZSH_HIGHLIGHT_STYLES[path_pathseparator]='fg=#ed8796,underline'
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=#cad3f5,underline'
ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]='fg=#ed8796,underline'
ZSH_HIGHLIGHT_STYLES[globbing]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=#c6a0f6'
#ZSH_HIGHLIGHT_STYLES[command-substitution]='fg=?'
#ZSH_HIGHLIGHT_STYLES[command-substitution-unquoted]='fg=?'
#ZSH_HIGHLIGHT_STYLES[process-substitution]='fg=?'
#ZSH_HIGHLIGHT_STYLES[arithmetic-expansion]='fg=?'
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-unclosed]='fg=#ee99a0'
ZSH_HIGHLIGHT_STYLES[redirection]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[arg0]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[default]='fg=#cad3f5'
ZSH_HIGHLIGHT_STYLES[cursor]='fg=#cad3f5'

View file

@ -59,7 +59,8 @@ fi
source "${ZINIT_HOME}/zinit.zsh"
# Add powerlevel10k prompt
zinit ice depth=1; zinit light romkatv/powerlevel10k
zinit ice depth=1;
# zinit light romkatv/powerlevel10k
# Add in zsh plugins
zinit light zsh-users/zsh-completions
@ -76,16 +77,12 @@ zinit snippet OMZP::command-not-found
zinit cdreplay -q
# Load powerlevel10k
[ -f ~/.p10k.zsh ] && source ~/.p10k.zsh
# Catppuccin for zsh-syntax-highlighting
source ~/.zsh/catppuccin_macchiato-zsh-syntax-highlighting.zsh
# Catppuccin for fzf
export FZF_DEFAULT_OPTS=" \
--color=bg+:#313244,bg:#1e1e2e,spinner:#f5e0dc,hl:#f38ba8 \
--color=fg:#cdd6f4,header:#f38ba8,info:#cba6f7,pointer:#f5e0dc \
--color=marker:#f5e0dc,fg+:#cdd6f4,prompt:#cba6f7,hl+:#f38ba8"
# Check that the function `starship_zle-keymap-select()` is defined.
# xref: https://github.com/starship/starship/issues/3418
type starship_zle-keymap-select-wrapped >/dev/null || \
{
eval "$(starship init zsh)"
}
# History settings
HISTFILE=~/.zsh_history
@ -191,4 +188,12 @@ if [[ -z "$TMUX" ]] && [[ $- == *i* ]]; then
fi
fi
if [[ -n "$TMUX" ]]; then
precmd() {
local name
name="$("$HOME/.config/tmux/tmux-rename-window.sh")"
tmux rename-window "$name"
}
fi
fastfetch