bspwm-pinephone-pro/.config/polybar/scripts/battery-combined-shell.sh

116 lines
2.6 KiB
Bash
Executable file

#!/bin/sh
PATH_AC_0="/sys/class/power_supply/rk818-battery"
BACKUP_PATH_AC_0="/sys/class/power_supply/axp20x-battery"
PATH_AC_1="/sys/class/power_supply/ip5xxx-battery"
PATH_BATTERY_0="/sys/class/power_supply/rk818-battery"
BACKUP_PATH_BATTERY_0="/sys/class/power_supply/axp20x-battery"
PATH_BATTERY_1="/sys/class/power_supply/ip5xxx-battery"
ac_0=""
ac_1=""
battery_level_0=0
battery_level_1=0
#battery_max_0=0
#battery_max_1=0
if [ ! -f "$PATH_AC_0/status" ]; then
PATH_AC_0=$BACKUP_PATH_AC_0
fi
ac_0=$(cat "$PATH_AC_0/status" 2>/dev/null)
if [ -f "$PATH_AC_1/status" ]; then
ac_1=$(cat "$PATH_AC_1/status" 2>/dev/null)
else
ac_1="-1"
fi
if [ ! -f "$PATH_BATTERY_0/capacity" ]; then
PATH_BATTERY_0=$BACKUP_PATH_BATTERY
fi
battery_level_0=$(cat "$PATH_BATTERY_0/capacity" 2>/dev/null)
if [ -f "$PATH_BATTERY_1/capacity" ]; then
battery_level_1=$(cat "$PATH_BATTERY_1/capacity" 2>/dev/null)
else
battery_level_1=-1
fi
# Sometimes the percentage is greater than 100, so we fix
# that here.
if [[ "$battery_level_0" -gt "100" ]]; then
battery_level_0=100
fi
if [[ "$battery_level_1" -gt "100" ]]; then
battery_level_1=100
fi
# If a battery is removed during runtime, the class files still
# remain, but you can't read them. This fixes that.
if [[ "$battery_level_0" == "" ]]; then
battery_level_0=-1
fi
if [[ "$battery_level_1" == "" ]]; then
battery_level_1=-1
fi
if [ "$ac_0" = "Charging" ] || [ "$ac_0" = "Full" ]; then
icon0=""
else
if [[ "$battery_level_0" -gt "97" ]]; then
icon0=""
elif [[ "$battery_level_0" -gt "85" ]]; then
icon0=""
elif [[ "$battery_level_0" -gt "60" ]]; then
icon0=""
elif [[ "$battery_level_0" -gt "35" ]]; then
icon0=""
elif [[ "$battery_level_0" -gt "10" ]]; then
icon0=""
elif [[ "$battery_level_0" -gt "0" ]]; then
icon0=""
else
icon0="!"
fi
fi
if [ "$ac_1" = "Charging" ] || [ "$ac_1" = "Full" ]; then
icon1=""
else
if [[ "$battery_level_1" -gt "97" ]]; then
icon1=""
elif [[ "$battery_level_1" -gt "85" ]]; then
icon1=""
elif [[ "$battery_level_1" -gt "60" ]]; then
icon1=""
elif [[ "$battery_level_1" -gt "35" ]]; then
icon1=""
elif [[ "$battery_level_1" -gt "10" ]]; then
icon1=""
elif [[ "$battery_level_1" -ge "0" ]]; then
icon1=""
else
icon1="!"
fi
fi
if [[ "$battery_level_0" -lt "0" ]]; then
#echo -n "$icon0 N/A"
:
else
echo -n "$icon0 $battery_level_0 %"
fi
if [[ "$battery_level_1" -lt "0" ]]; then
#echo -n "$icon1 N/A"
:
else
echo -n " $icon1 $battery_level_1 %"
fi