Skip to content

Instantly share code, notes, and snippets.

@BrandonDusseau
Last active August 29, 2015 14:24
Show Gist options
  • Save BrandonDusseau/c39a27e64f76c28fb201 to your computer and use it in GitHub Desktop.
Save BrandonDusseau/c39a27e64f76c28fb201 to your computer and use it in GitHub Desktop.
Simple Battery Level Script
#!/bin/sh
upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep 'percentage\|state' | sed ':a;N;$!ba;s/\s\{1,\}state\:\s\{1,\}\(.*\)\n\s\{1,\}percentage\:\s\{1,\}\(.*\)/Battery level: \2 (\1)/'

#batlvl.sh# This simple shell script will output a summarized battery status on Linux by utilizing the output of the upower command.

$ batlvl.sh
Battery level: 94% (charging)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment