Last active
October 29, 2015 10:26
-
-
Save redacted/99a45ede4158a24282fe to your computer and use it in GitHub Desktop.
parts of probably oh-my-zsh for battery monitoring on macs
This file contains hidden or 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
function battery_pct() { | |
typeset -F maxcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //') | |
typeset -F currentcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //') | |
integer i=$(((currentcapacity/maxcapacity) * 100)) | |
echo $i | |
} | |
function battery_pct_remaining() { | |
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then | |
battery_pct | |
else | |
echo "External Power" | |
fi | |
} | |
function battery_pct_prompt () { | |
if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then | |
b=$(battery_pct_remaining) | |
if [ $b -gt 50 ] ; then | |
color='green' | |
elif [ $b -gt 20 ] ; then | |
color='yellow' | |
else | |
color='red' | |
fi | |
echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}" | |
else | |
echo "∞" | |
fi | |
} | |
# RPROMPT='$(battery_pct_prompt)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment