diff options
author | Amin Bandali <bandali@kelar.org> | 2024-09-19 12:14:57 -0400 |
---|---|---|
committer | Amin Bandali <bandali@kelar.org> | 2024-09-19 12:14:57 -0400 |
commit | a31fef36ff03a057a743fdc1c2d234270137caa0 (patch) | |
tree | fd33981b01aff72f24fc3d78d7f20826c902bb0a /.local/bin/b-bar | |
parent | 66f39fc4503139c226217e37aa9eb309c01ddcb2 (diff) | |
download | configs-a31fef36ff03a057a743fdc1c2d234270137caa0.tar.gz configs-a31fef36ff03a057a743fdc1c2d234270137caa0.tar.xz configs-a31fef36ff03a057a743fdc1c2d234270137caa0.zip |
Get b-bar battery from GNU Emacs if available
Diffstat (limited to '')
-rwxr-xr-x | .local/bin/b-bar | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/.local/bin/b-bar b/.local/bin/b-bar index 8641238..04ae6bb 100755 --- a/.local/bin/b-bar +++ b/.local/bin/b-bar @@ -18,28 +18,35 @@ do bar="$cpu1 $cpu2 $nrbr | $bar" ;; adelita|anahita) - [ "$host" = "anahita" ] && bdev="sbs_9_000b" || bdev="BAT0" - b0="$(upower -i /org/freedesktop/UPower/devices/battery_$bdev)" - batstat="$(echo "$b0" | awk '/state/{print $NF}')" - if [ "$batstat" = "discharging" ]; then - batstat='-' - elif [ "$batstat" = "charging" ]; then - batstat='+' + if [ -x "$(command -v emacsclient)" ]; then + embat='(battery-format b/battery-format (funcall battery-status-function))' + bat="$(emacsclient -e "$embat")" + bat="${bat%\"}" + bat="${bat#\"}" + else + [ "$host" = "anahita" ] && bdev="sbs_9_000b" || bdev="BAT0" + b0="$(upower -i /org/freedesktop/UPower/devices/battery_$bdev)" + batstat="$(echo "$b0" | awk '/state/{print $NF}')" + if [ "$batstat" = "discharging" ]; then + batstat='-' + elif [ "$batstat" = "charging" ]; then + batstat='+' + fi + batcap="$(echo "$b0" | awk '/percentage/ \ + {sub(/\%$/, "", $NF); \ + print $NF}')" + battime="$(echo "$b0" | awk -F: '/time to (full|empty)/ \ + {sub(/^[ \t]+/, "", $NF); \ + sub(/\ hours?$/, "h", $NF); \ + print $NF}')" + bat="${batcap}$batstat $battime" fi - batcap="$(echo "$b0" | awk '/percentage/ \ - {sub(/\%$/, "", $NF); \ - print $NF}')" - battime="$(echo "$b0" | awk -F: '/time to (full|empty)/ \ - {sub(/^[ \t]+/, "", $NF); \ - sub(/\ hours?$/, "h", $NF); \ - print $NF}')" - bat="${batcap}$batstat $battime" bar="$bat | $bar" ;; *) ;; esac - printf "$bar\n" + printf '%s\n' "$bar" sleep 5 done |