Created
April 3, 2012 20:33
-
-
Save alexmcpherson/2295304 to your computer and use it in GitHub Desktop.
Ruby Battery Level
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
#!/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 |
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
//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