Add community scripts for i3blocks
This commit is contained in:
42
.local/bin/i3scripts/contrib/battery
Executable file
42
.local/bin/i3scripts/contrib/battery
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user