mirror of
https://git.adityakumar.xyz/nix-conf.git
synced 2025-02-22 15:50:01 +00:00
30 lines
680 B
Bash
30 lines
680 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
############ Variables ############
|
||
|
enable_battery=false
|
||
|
battery_charging=false
|
||
|
|
||
|
####### Check availability ########
|
||
|
for battery in /sys/class/power_supply/*BAT*; do
|
||
|
if [[ -f "$battery/uevent" ]]; then
|
||
|
enable_battery=true
|
||
|
if [[ $(cat /sys/class/power_supply/*/status | head -1) == "Charging" ]]; then
|
||
|
battery_charging=true
|
||
|
fi
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
############# Output #############
|
||
|
if [[ $enable_battery == true ]]; then
|
||
|
if [[ $battery_charging == true ]]; then
|
||
|
echo -n "(+) "
|
||
|
fi
|
||
|
echo -n "$(cat /sys/class/power_supply/*/capacity | head -1)"%
|
||
|
if [[ $battery_charging == false ]]; then
|
||
|
echo -n " remaining"
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
echo ''
|