Created
March 3, 2012 19:06
-
-
Save Seich/1967568 to your computer and use it in GitHub Desktop.
Zsh battery reporting for Ubuntu
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
# 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 = '%{[32m%}' | |
color_yellow = '%{[1;33m%}' | |
color_red = '%{[31m%}' | |
color_reset = '%{[00m%}' | |
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 |
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
# 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