Created
November 7, 2014 02:42
-
-
Save sarcasticsimba/dd13d9488ec1bd9cb26d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
full=$(pmset -g batt | { read; read n full; echo "$full"; }) | |
batt=$(echo "$full" | cut -d';' -f1 | tr -d '%') | |
status=$(echo "$full" | cut -d';' -f2 | tr -d ' ') | |
time=$(echo "$full" | cut -d';' -f3 | sed 's/^ *//') | |
noc=$'\e[39m' | |
if (($batt >= 66)); then battc=$'\e[32m'; | |
elif (($batt >= 33)); then battc=$'\e[33m'; | |
else battc=$'\e[31m'; | |
fi; | |
if [ "$status" == "discharging" ]; then | |
statc=$'\e[31m'; | |
elif [ "$status" == "charging" ]; then | |
statc=$'\e[32m'; | |
elif [ "$status" == "charged" ]; then | |
statc=$'\e[32m'; | |
else | |
statc=$'\e[33m'; | |
fi | |
echo "$battc$batt%$noc | $statc$status$noc | $time" |
On osx 10.12.6 there seems to be an additional id field at the beginning
#! /bin/bash
full=$(pmset -g batt | { read; read n full; echo "$full"; })
batt=$(echo "$full" | awk '/(%);/{print $2}' | cut -d'%' -f1)
status=$(echo "$full" | cut -d';' -f2 | tr -d ' ')
time=$(echo "$full" | awk '/(%);/{print $4 " " $5}') #cut -d';' -f3 | sed 's/^ *//'
noc=$'\e[39m'
if (($batt >= 66)); then battc=$'\e[32m';
elif (($batt >= 33)); then battc=$'\e[33m';
else battc=$'\e[31m';
fi;
if [ "$status" == "discharging" ]; then
statc=$'\e[31m';
elif [ "$status" == "charging" ]; then
statc=$'\e[32m';
elif [ "$status" == "charged" ]; then
statc=$'\e[32m';
else
statc=$'\e[33m';
fi
echo "$battc$batt%$noc | $statc$status$noc | $time"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those that use a magic mouse, this will give you battery remaining of that device, in relevant color scheme to battery percentage.
EDIT: Adding a case for when the mouse is not present, or turned off; prevents bash errors.