31 lines
862 B
Bash
Executable file
31 lines
862 B
Bash
Executable file
#!/bin/bash
|
|
|
|
|
|
# Loop through all attached batteries and format the info
|
|
for battery in /sys/class/power_supply/BAT?*; do
|
|
# If non-first battery, print a space separator.
|
|
[ -n "${capacity+x}" ] && printf " "
|
|
# Sets up the status and capacity
|
|
case "$(cat "$battery/status" 2>/dev/null)" in
|
|
"Full") status=" " ;;
|
|
"Discharging") status=" " ;;
|
|
"Charging") status=" " ;;
|
|
"Not charging") status=" " ;;
|
|
"Unknown") status=" " ;;
|
|
esac
|
|
capacity=$(cat "$battery/capacity" 2>/dev/null)
|
|
# Will make a warn variable if discharging and low
|
|
# [ "$status" = " " ] && [ "$capacity" -le 25 ] && notify-send --urgency=critical "System Management" "Battery low."
|
|
# Prints the info
|
|
done
|
|
|
|
|
|
|
|
if [[ "$1" == "--cap" ]]; then
|
|
echo $capacity
|
|
elif [[ "$1" == "--stat" ]]; then
|
|
echo $status
|
|
elif [[ "$1" == "--full" ]]; then
|
|
echo "$status $capacity%"
|
|
fi
|