Created
April 17, 2012 21:17
-
-
Save milin/2409130 to your computer and use it in GitHub Desktop.
Battery Status Zsh script code.
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
setprompt(){ | |
if which acpi &> /dev/null; then | |
local BATTSTATE="$(acpi -b)" | |
local BATTPRCNT="$(echo ${BATTSTATE[(w)4]}|sed -r 's/(^[0-9]+).*/\1/')" | |
local BATTSTATUS="$(echo ${BATTSTATE[(w)3]})" | |
if [[ "${BATTSTATUS}" = "Discharging," ]]; then | |
if [[ -z "${BATTPRCNT}" ]]; then | |
PR_BATTERY="" | |
elif [[ "${BATTPRCNT}" -lt 15 ]]; then | |
PR_BATTERY="${fg[red]%}|${fg[red]} batt:${BATTPRCNT}%%" | |
elif [[ "${BATTPRCNT}" -lt 60 ]]; then | |
PR_BATTERY="${fg[red]%}|${fg[yellow]} batt:${BATTPRCNT}%%" | |
elif [[ "${BATTPRCNT}" -lt 100 ]]; then | |
PR_BATTERY="${fg[red]%}|${fg[green]} batt:${BATTPRCNT}%%" | |
else | |
PR_BATTERY="" | |
fi | |
else | |
PR_BATTERY="" | |
fi | |
fi | |
PROMPT='$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}%{$fg[yellow]%}%m%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}${PR_BATTERY%}%{$reset_color%}%{$fg[red]%}|%{$reset_color%}$(git_prompt_info)$(svn_prompt_info)%{$reset_color%}%{$fg[cyan]%}⇒%{$reset_color%} ' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment