diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2022-02-26 20:31:12 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2022-02-26 20:31:12 +0530 |
commit | 85ae438fbc238fe56bcb1c10a12ec52365053cb6 (patch) | |
tree | 7aa2c802739657f22fd8de735207b27fc6e7e8a9 /modules/battery | |
download | dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.tar.gz dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.tar.bz2 dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.zip |
dwmbar dotfiles
Diffstat (limited to 'modules/battery')
-rwxr-xr-x | modules/battery | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/battery b/modules/battery new file mode 100755 index 0000000..9069c96 --- /dev/null +++ b/modules/battery @@ -0,0 +1,43 @@ +#!/bin/bash + +# Prints out battery percentage + +CHARGING_ICON='⚡ ' +WARNING_ICON='⚠️ ' +BATTERY_FULL_ICON='' +BATTERY_2_ICON='' +BATTERY_3_ICON='' +BATTERY_4_ICON='' + +FULL_AT=98 + +BAT_ICON="" +ICON="" + +get_battery() +{ + # The vast majority of people only use one battery. + + if [ -d /sys/class/power_supply/BAT0 ]; then + capacity=$(cat /sys/class/power_supply/BAT0/capacity) + charging=$(cat /sys/class/power_supply/BAT0/status) + if [[ "$charging" == "Charging" ]]; then + ICON="$CHARGING_ICON" + elif [[ $capacity -le 25 ]]; then + ICON="$WARNING_ICON" + fi + + if [[ $capacity -ge $FULL_AT ]]; then + BAT_ICON=$BATTERY_FULL_ICON + elif [[ $capacity -le 25 ]]; then + BAT_ICON=$BATTERY_4_ICON + elif [[ $capacity -le 60 ]]; then + BAT_ICON=$BATTERY_3_ICON + elif [[ $capacity -le $FULL_AT ]]; then + BAT_ICON=$BATTERY_2_ICON + fi + fi + echo "$ICON$BAT_ICON $capacity%" +} + +get_battery |