Created
July 7, 2017 08:00
-
-
Save alepee/f01fa497df62473e2cbf4cb886b5a463 to your computer and use it in GitHub Desktop.
display battery status in iTerm2 RPROMPT and warn if battery is going low (<5%)
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
## | |
# depends on battery zsh plugin | |
# https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/battery/battery.plugin.zsh | |
## | |
if [ "$(ioreg -rc "AppleSmartBattery" | wc -m)" -gt "0" ]; then | |
battery_charge() { | |
read -r last_battery_pct < $HOME/.battery | |
curr_battery_pct="$(battery_pct)" | |
echo $curr_battery_pct > $HOME/.battery | |
battery_is_charging \ | |
&& prompt="⚡" \ | |
|| prompt="$(battery_pct_prompt)" | |
echo "$prompt" 2> /dev/null | |
if [ "$curr_battery_pct" -lt "6" ] && [ "$curr_battery_pct" -lt "$last_battery_pct" ]; then | |
say -v Daniel "$curr_battery_pct% battery remaining" & | |
fi | |
} | |
RPROMPT='$(battery_charge)' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment