Show battery status in sway bar

This commit is contained in:
KK
2026-06-26 00:05:57 +02:00
parent 9fd1ba70a3
commit ac1005b842
2 changed files with 20 additions and 10 deletions

View File

@@ -7,21 +7,28 @@ print_status() {
brightness=$(brightnessctl -m 2>/dev/null | awk -F, '{print $4}') brightness=$(brightnessctl -m 2>/dev/null | awk -F, '{print $4}')
voxtype_state=$(voxtype status 2>/dev/null) battery_device=$(upower -e 2>/dev/null | grep -m 1 battery)
case "$voxtype_state" in if [ -n "$battery_device" ]; then
recording) voxtype=' | VOX REC' ;; battery=$(upower -i "$battery_device" 2>/dev/null | awk '
transcribing) voxtype=' | VOX ...' ;; /state/ { state=$2 }
*) voxtype='' ;; /percentage/ { percentage=$2 }
esac END {
if (percentage != "") {
printf "%s", percentage
if (state != "") printf " %s", state
}
}
')
fi
printf 'VOL %s | BRI %s%s | %s\n' "${volume:-n/a}" "${brightness:-n/a}" "$voxtype" "$(date +'%Y-%m-%d %H:%M:%S')" printf 'VOL %s | BRI %s | BAT %s | %s\n' "${volume:-n/a}" "${brightness:-n/a}" "${battery:-n/a}" "$(date +'%Y-%m-%d %H:%M:%S')"
} }
trap print_status USR1 trap print_status USR1
print_status print_status
while :; do while :; do
sleep 1 & sleep 60 &
wait $! wait $!
print_status print_status
done done

View File

@@ -1,6 +1,9 @@
SRC=$HOME/dotfiles SRC=$HOME/dotfiles
rm $HOME/.bashrc [ -e $HOME/.bashrc ] && echo "I won't install ~/.bashrc because there is already a file like that; skipping setup for this file."
rm $HOME/.bash_profile [ -e $HOME/.vimrc ] && echo "I won't install ~/.vimrc because there is already a file like that; skipping setup for this file."
[ -e $HOME/.bash_profile ] && echo "I won't install ~/.bash_profile because there is already a file like that; skipping setup for this file."
[ -d $HOME/.config ] && echo "I won't install ~/.config because there is already a directory like that; skipping setup for this directory."
[ -d $HOME/bin ] && echo "I won't install ~/bin because there is already a directory like that; skipping setup for this directory."
ln -sf $SRC/.bashrc $HOME/.bashrc ln -sf $SRC/.bashrc $HOME/.bashrc
ln -sf $SRC/.vimrc $HOME/.vimrc ln -sf $SRC/.vimrc $HOME/.vimrc
ln -sf $SRC/.bash_profile $HOME/.bash_profile ln -sf $SRC/.bash_profile $HOME/.bash_profile