diff options
| author | Skladnayazebra <skladnayazebra@gmail.com> | 2025-11-06 22:05:08 +0100 |
|---|---|---|
| committer | Skladnayazebra <skladnayazebra@gmail.com> | 2025-11-06 22:05:08 +0100 |
| commit | 10e12dc6af3e176e0ad6ede932ceea7b128de904 (patch) | |
| tree | d25a4618f8b547aab2e3e3fdb8676cd88cc9c006 | |
| parent | a28cfb177d59fba97de6c28138dcb2646a7662e9 (diff) | |
Add battery status as an external shell script
| -rwxr-xr-x | tmux/battery.sh | 17 | ||||
| -rw-r--r-- | tmux/tmux.conf | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/tmux/battery.sh b/tmux/battery.sh new file mode 100755 index 0000000..26b3388 --- /dev/null +++ b/tmux/battery.sh @@ -0,0 +1,17 @@ +round() { awk -v n=$1 -v d=$2 'BEGIN{print int((n+d/2)/d) * d}'; } + +upower -i /org/freedesktop/UPower/devices/DisplayDevice | awk '/percentage:/ {print $2}' | { + read s; + lvl=$(round "${s%%%}" 10); + if [ $lvl -eq "10" ]; then printf ""; fi + if [ $lvl -eq "20" ]; then printf ""; fi + if [ $lvl -eq "30" ]; then printf ""; fi + if [ $lvl -eq "40" ]; then printf ""; fi + if [ $lvl -eq "50" ]; then printf ""; fi + if [ $lvl -eq "60" ]; then printf ""; fi + if [ $lvl -eq "70" ]; then printf ""; fi + if [ $lvl -eq "80" ]; then printf ""; fi + if [ $lvl -eq "90" ]; then printf ""; fi + if [ $lvl -eq "100" ]; then printf ""; fi + printf " %.0f%%" "${s%%%}"; +} diff --git a/tmux/tmux.conf b/tmux/tmux.conf index 2267017..0b9d45f 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -26,4 +26,4 @@ set-window-option -g window-status-current-format ' #I:#W ' bind '"' split-window -v -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}" -set-window-option -g status-right "%H:%M %d-%b-%y #(upower -i /org/freedesktop/UPower/devices/DisplayDevice | awk '/percentage:/ {print \$2}' | bash -c 'read s; printf \"%.0f%%%%\" \"\${s%%%}\"') " +set-window-option -g status-right "%H:%M %d-%b-%y #($HOME/.config/tmux/battery.sh) " |
