Skip to content

Instantly share code, notes, and snippets.

@alepee
Created July 7, 2017 08:00
Show Gist options
  • Save alepee/f01fa497df62473e2cbf4cb886b5a463 to your computer and use it in GitHub Desktop.
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%)
##
# 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