summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.emacs.d/init.el3
-rwxr-xr-x.local/bin/b-bar39
2 files changed, 25 insertions, 17 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 0c35928..97f515e 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -215,9 +215,10 @@ plain variables. This means that `setopt' will execute any
(unless (display-graphic-p)
(display-time-mode)))
+(defvar b/battery-format "%p%b %t")
(run-with-idle-timer 0.1 nil #'require 'battery)
(with-eval-after-load 'battery
- (setopt battery-mode-line-format " [%b%p%% %t]")
+ (setopt battery-mode-line-format (format " [%s]" b/battery-format))
(display-battery-mode))
(run-with-idle-timer 0.5 nil #'require 'winner)
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