Show battery in tmux status

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-04-19 11:06:31 +02:00
parent b7d5017ced
commit addb61367c
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 22 additions and 1 deletions

View file

@ -34,7 +34,7 @@ set -g status-justify left
set -g status-left-length 40
set -g status-right-length 140
set -g status-left '#[fg=green]#H#[default] '
set -g status-right '#[fg=red,bg=default]#(check_config)#[default] #[fg=red,bg=default]#(tmux-chrony-timediff)#[default] #[fg=white,bg=red]#(tmux-reboot-required)#[default] #[fg=red,dim,bg=default]#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") #[fg=white,bg=default]%a, %H:%M:%S#[default] #[fg=blue,bright]%Y-%m-%d (KW %V) '
set -g status-right '#[fg=red,bg=default]#(check_config)#[default] #[fg=red,bg=default]#(tmux-chrony-timediff)#[default] #[fg=white,bg=red]#(tmux-reboot-required)#[default] #[fg=white,bg=default]#(tmux-battery)#[default] #[fg=green,bg=default]#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") #[fg=white,bg=default]%a, %H:%M:%S#[default] #[fg=blue,bright]%Y-%m-%d (KW %V) '
# C-b is not acceptable -- Vim uses it
set-option -g prefix C-a

21
bin/tmux-battery Executable file
View file

@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail
SYM_ADAPTER="⚡️"
SYM_BATTERY="🔋"
BATTERY=/sys/class/power_supply/BAT0
AC=/sys/class/power_supply/AC
[ -e ${BATTERY} ] || { echo "No battery" >&2; exit 0; }
[ -e ${AC} ] || { echo "No ac" >&2; exit 0; }
CAPACITY=$(cat ${BATTERY}/capacity)
AC_CONNECT=$(cat ${AC}/online)
if [ ${AC_CONNECT} -eq 0 ]; then
SYM=${SYM_BATTERY}
else
SYM=${SYM_ADAPTER}
fi
echo "${SYM} ${CAPACITY}%"