43 lines
706 B
Bash
Executable File
43 lines
706 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
################################
|
|
# Shows info about connected batteries.
|
|
#
|
|
# Dependencies:
|
|
# - acpi
|
|
#
|
|
# @return {Number(%)}: Current battery charge
|
|
################################
|
|
|
|
dir=$(dirname $0)
|
|
source $dir/util.sh
|
|
|
|
full=""
|
|
short=""
|
|
status=0
|
|
|
|
# Exit if no battery was found
|
|
if [ "$(acpi)" == "" ]; then exit 0; fi
|
|
|
|
state=$(acpi | sed -n 's/Battery [0-9]: \([A-Z]\).*, .*/\1/p')
|
|
chg=$(acpi | sed -n 's/Battery [0-9]:.*, \([0-9]\{1,3\}\)%.*/\1/p')
|
|
|
|
# Charging or Unknown
|
|
if [ $state = "C" ] || [ $state = "U" ]; then
|
|
icon=""
|
|
else
|
|
if [ $chg -le 10 ]; then
|
|
icon=""
|
|
status=33
|
|
else
|
|
icon=""
|
|
fi
|
|
fi
|
|
|
|
full="$icon $chg%"
|
|
short="$chg%"
|
|
|
|
echo $full
|
|
echo $short
|
|
exit $status
|