diff options
author | David Runge <dave@sleepmap.de> | 2016-03-11 10:42:47 +0100 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2016-03-11 10:42:47 +0100 |
commit | 811fa21a9df0c136cafab935b6882b7541a22203 (patch) | |
tree | 939e14e8137940ea343f787d93a3c2fd77574b30 /bin/get_battery_status | |
parent | 5c859c1a873d5be412926ce5b06426791b5e78a0 (diff) | |
download | dotfiles-811fa21a9df0c136cafab935b6882b7541a22203.tar.gz dotfiles-811fa21a9df0c136cafab935b6882b7541a22203.tar.bz2 dotfiles-811fa21a9df0c136cafab935b6882b7541a22203.tar.xz dotfiles-811fa21a9df0c136cafab935b6882b7541a22203.zip |
bin/get_*: Adding helper scripts to be used in tmux.
Diffstat (limited to 'bin/get_battery_status')
-rwxr-xr-x | bin/get_battery_status | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bin/get_battery_status b/bin/get_battery_status new file mode 100755 index 0000000..5ad18ce --- /dev/null +++ b/bin/get_battery_status @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +acpi_output="" +battery_number=0 +battery_percentage=0 +battery_remaining="" + +if [ -x /usr/bin/acpi ]; then + acpi_output=$(/usr/bin/acpi -b) + battery_number=$(echo $acpi_output|cut -d':' -f1|cut -d' ' -f2) + battery_state=$(echo $acpi_output|cut -d' ' -f3) + battery_state=${battery_state%","} + battery_percentage=$(echo $acpi_output|cut -d' ' -f4) + battery_percentage=${battery_percentage%","} + battery_percentage=${battery_percentage%"%"} + if [ $battery_state = "Discharging" ]; then + battery_remaining=$(echo $acpi_output|cut -d' ' -f5) + echo "$battery_percentage% ($battery_remaining)" + else + echo "$battery_percentage%" + fi +else + exit 1 +fi + |