Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # encoding: utf-8
  2.  
  3. # Get the current battery status percentage.
  4. battery_status = `acpi`
  5. charge = battery_status.match(/\d*%/)[0].chop.to_i
  6.  
  7. # Calculate the number of charged slots.
  8. total_slots = 10
  9.  
  10. filled = "▸" * (charge/total_slots).ceil
  11. empty = "▹" * (total_slots - filled.length)
  12. output = filled + empty
  13.  
  14.  
  15. # Colors
  16. color_green = '%{%}'
  17. color_yellow = '%{%}'
  18. color_red = '%{%}'
  19. color_reset = '%{%}'
  20.  
  21. color_out = case
  22.   when filled.length > 6
  23.     color_green
  24.   when filled.length > 4
  25.     color_yellow
  26.   else
  27.     color_red
  28. end
  29.  
  30. # Return the charge.
  31. puts color_out + output + color_reset