dotfiles/.config/xmobar/scripts/battery.sh

79 lines
1.9 KiB
Bash
Raw Normal View History

2022-11-01 00:48:17 +00:00
#!/bin/bash
#Check if its laptop of pc with hostnamectl
pctype=$(hostnamectl | grep -Po '(Chassis: )(\w+)' | sed 's/Chassis: //')
if [ "$pctype" == "desktop" ];
2023-09-18 07:20:52 +01:00
then
#Check if any connected device has a battery with upower
xm3bat=$(upower -i /org/freedesktop/UPower/devices/headset_dev_94_DB_56_AB_B5_D4 | grep -Po '(percentage: *)(\d+)' | sed 's/\s*percentage: //' | xargs)
if [ "$xm3bat" == 0 ];
then
echo ""
exit 0
fi
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰋋</fn><fc=#AAC0F0> $xm3bat% </fc>"
exit 0
2023-09-18 07:20:52 +01:00
fi
2022-11-01 00:48:17 +00:00
batLevel=$(acpi --battery | grep -Po '(\d+)\%' | sed 's/%//')
charging=$(acpi --ac-adapter | grep -Po '(off-line|on-line)')
if [ $batLevel -le 20 ];
then
if [ $charging == "on-line" ];
then
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰂆 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
else
2023-10-13 10:33:49 +01:00
echo "<fn=4>󰁻 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
fi
elif [ $batLevel -le 30 ];
then
if [ $charging == "on-line" ];
then
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰂇 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
else
2023-10-13 10:33:49 +01:00
echo "<fn=4>󰁼 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
fi
elif [ $batLevel -le 40 ];
then
if [ $charging == "on-line" ];
then
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰂈 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
else
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰁽 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
fi
elif [ $batLevel -le 60 ];
then
if [ $charging == "on-line" ];
then
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰂉 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
else
2023-10-13 10:33:49 +01:00
echo "<fn=4>󰁿 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
fi
elif [ $batLevel -le 80 ];
then
if [ $charging == "on-line" ];
then
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰂊 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
else
2023-10-13 10:33:49 +01:00
echo "<fn=4>󰂁 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
fi
elif [ $batLevel -le 95 ];
then
if [ $charging == "on-line" ];
then
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰂋 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
else
2023-10-13 10:33:49 +01:00
echo "<fn=4>󰂂 </fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
fi
else
2022-11-01 00:48:17 +00:00
if [ $charging == "on-line" ];
then
2023-10-13 10:33:49 +01:00
echo "<fn=3>󰂅</fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
else
2023-10-13 10:33:49 +01:00
echo "<fn=4>󰁹</fn> <fc=#AAC0F0> $batLevel% </fc>"
2022-11-01 00:48:17 +00:00
fi
fi