diff options
Diffstat (limited to '.local/bin/b-bar')
-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 |