Ruby Battery Level
#!/usr/bin/env ruby | |
# coding: utf-8 | |
output = `pmset -g batt` | |
percent_battery = output.match(/\d+\%/).to_s.gsub("%","").to_f | |
empty = '▹' | |
filled = '▸' | |
color_green = '%{[32m%}' | |
color_yellow = '%{[1;33m%}' | |
color_red = '%{[31m%}' | |
color_reset = '%{[00m%}' | |
color = color_green | |
if percent_battery < 20 | |
color = color_red | |
elsif percent_battery < 50 | |
color = color_yellow | |
end | |
num_filled = (percent_battery/10).ceil | |
puts color + '[' + (filled * num_filled) + empty * (10-num_filled) + ']' + color_reset |
//Other prompt info as long as it doesn't set RPROMPT | |
RPROMPT='$(battery.rb)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment