Skip to content

Instantly share code, notes, and snippets.

@ueokande
Last active August 29, 2015 14:09
Show Gist options
  • Save ueokande/69f1c5494d7fb3779fb7 to your computer and use it in GitHub Desktop.
Save ueokande/69f1c5494d7fb3779fb7 to your computer and use it in GitHub Desktop.
Get buttery state
#!/bin/sh
base=(/sys/class/power_supply/BAT* )
base=${base[0]}
if [ ! -d $base ]; then
echo 'Battery is not detected.' 1>&2
exit 1;
fi
now=`cat ${base}/energy_now`
full=`cat ${base}/energy_full`
percent=$((100 * $now / $full))
if [ $percent -le 20 ]; then
printf '\e[31m'
elif [ $percent -le 50 ]; then
printf '\e[33m'
fi
echo $percent'%'
printf '\e[0m'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment