tmux-kanagawa/scripts/battery.sh
Uttarayan Mondal a8ab770bec Added powerline symbols
Changed it so that battery can be read from BAT1 and BAT0
2020-05-11 23:38:13 +05:30

62 lines
853 B
Bash
Executable file

#!/usr/bin/env bash
BAT=$(ls /sys/class/power_supply/BAT* | head -1)
battery_percent()
{
# Check OS
case $(uname -s) in
Linux)
cat $BAT/capacity
;;
Darwin)
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability
;;
*)
;;
esac
}
battery_status()
{
# Check OS
case $(uname -s) in
Linux)
status=$(cat $BAT/status)
;;
Darwin)
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2)
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
# leaving empty - TODO - windows compatability
;;
*)
;;
esac
if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then
echo ''
else
echo 'AC '
fi
}
main()
{
bat_stat=$(battery_status)
bat_perc=$(battery_percent)
echo "$bat_stat$bat_perc"
}
#run main driver program
main