Skip to content

Instantly share code, notes, and snippets.

@amir
Created November 14, 2008 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amir/24805 to your computer and use it in GitHub Desktop.
Save amir/24805 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -ne 1 ]; then
battery_id='BAT0'
else
battery_id=$1
fi
battery_max=`cat /proc/acpi/battery/$battery_id/info | head -3 | tail -1 | awk '{print $4}'`
if [ "$(cat /proc/acpi/battery/$battery_id/state | grep -o discharging)" == "discharging" ]; then
prepend="-"
else
prepend="+"
fi
battery_current=`cat /proc/acpi/battery/$battery_id/state | head -5 | tail -1 | awk '{print $3}'`
battery_level=$((100*$battery_current/$battery_max))
echo "$prepend$battery_level"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment