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:
parent
886818cd1f
commit
93e41aef46
11 changed files with 412 additions and 1874 deletions
174
home/.config/confutils/get-battery.sh
Executable file
174
home/.config/confutils/get-battery.sh
Executable 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"
|
||||
4
home/.config/starship.toml
Normal file
4
home/.config/starship.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Get editor completions based on the config schema
|
||||
"$schema" = 'https://starship.rs/config-schema.json'
|
||||
|
||||
add_newline = true
|
||||
44
home/.config/tmux/tmux-rename-window.sh
Executable file
44
home/.config/tmux/tmux-rename-window.sh
Executable 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
|
||||
|
||||
15
home/.config/tmux/tmux-status-right.sh
Executable file
15
home/.config/tmux/tmux-status-right.sh
Executable 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue