
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 0.60 KB | hits: 17 | expires: Never
# 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