Skip to content

Instantly share code, notes, and snippets.

@alexmcpherson
Created April 3, 2012 20:33
Show Gist options
  • Save alexmcpherson/2295304 to your computer and use it in GitHub Desktop.
Save alexmcpherson/2295304 to your computer and use it in GitHub Desktop.
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 = '%{%}'
color_yellow = '%{%}'
color_red = '%{%}'
color_reset = '%{%}'
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