aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorDavid Runge <david.runge@native-instruments.de>2018-04-23 08:38:57 +0200
committerDavid Runge <david.runge@native-instruments.de>2018-04-23 08:38:57 +0200
commit10b20223895f1b1bd154c96d96e55ad77291147b (patch)
tree47510f41a929095234f70da0797f994f467e0597 /bin
parentea4515f490085e6a806ecb12e6d33728ce9edaee (diff)
downloaddotfiles-10b20223895f1b1bd154c96d96e55ad77291147b.tar.gz
dotfiles-10b20223895f1b1bd154c96d96e55ad77291147b.tar.bz2
dotfiles-10b20223895f1b1bd154c96d96e55ad77291147b.tar.xz
dotfiles-10b20223895f1b1bd154c96d96e55ad77291147b.zip
bin/get_battery_status: Making the script cross-platform (macOS is now also supported).
Diffstat (limited to 'bin')
-rwxr-xr-xbin/get_battery_status40
1 files changed, 27 insertions, 13 deletions
diff --git a/bin/get_battery_status b/bin/get_battery_status
index 57af321..3597acb 100755
--- a/bin/get_battery_status
+++ b/bin/get_battery_status
@@ -3,25 +3,39 @@ set -euo pipefail
IFS=$'\n\t'
acpi_output=""
+pmset_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%","}
+if [ $(uname) == "Darwin" ]; then
+ pmset_output="$(pmset -g batt| tail -n1)"
+ battery_percentage="$(echo $pmset_output| cut -d';' -f1| cut -d' ' -f4)"
battery_percentage=${battery_percentage%"%"}
- if [ $battery_number -ge 0 ]; then
- if [ $battery_state = "Discharging" ]; then
- battery_remaining=$(echo $acpi_output|cut -d' ' -f5)
- echo "$battery_percentage% ($battery_remaining)"
- else
- echo "$battery_percentage%"
+ if [[ "$pmset_output" == *"discharging"* ]]; then
+ battery_remaining="$(echo $pmset_output| cut -d';' -f3| cut -d' ' -f2)"
+ echo "$battery_percentage% ($battery_remaining)"
+ else
+ echo "$battery_percentage%"
+ fi
+else
+ 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_number -ge 0 ]; then
+ if [ $battery_state = "Discharging" ]; then
+ battery_remaining=$(echo $acpi_output|cut -d' ' -f5)
+ echo "$battery_percentage% ($battery_remaining)"
+ else
+ echo "$battery_percentage%"
+ fi
fi
fi
fi
+
exit 0