Skip to content

Instantly share code, notes, and snippets.

@Seich
Created March 3, 2012 19:06
Show Gist options
  • Save Seich/1967568 to your computer and use it in GitHub Desktop.
Save Seich/1967568 to your computer and use it in GitHub Desktop.
Zsh battery reporting for Ubuntu
# encoding: utf-8
# Get the current battery status percentage.
battery_status = `acpi`
charge = battery_status.match(/\d*%/)[0].chop.to_i
# Calculate the number of charged slots.
total_slots = 10
filled = "▸" * (charge/total_slots).ceil
empty = "▹" * (total_slots - filled.length)
output = filled + empty
# Colors
color_green = '%{%}'
color_yellow = '%{%}'
color_red = '%{%}'
color_reset = '%{%}'
color_out = case
when filled.length > 6
color_green
when filled.length > 4
color_yellow
else
color_red
end
# Return the charge.
puts color_out + output + color_reset
# Based off http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
function collapse_pwd {
echo $(pwd | sed -e "s,^$HOME,~,")
}
function prompt_char {
git branch >/dev/null 2>/dev/null && echo '±' && return
echo '○'
}
function battery_charge {
#echo `acpi | grep ...% -o` 2>/dev/null
echo `/home/seich/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /home/seich/.bin/batteryMeter.rb` 2>/dev/null
}
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
}
PROMPT='
%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}$(collapse_pwd)%{$reset_color%}$(git_prompt_info)
$(virtualenv_info)$(prompt_char) '
RPROMPT='$(battery_charge)'
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}!"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN=""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment