Created
October 21, 2012 08:53
-
-
Save pimeys/3926408 to your computer and use it in GitHub Desktop.
Battery indicator for Xmobar
This file contains hidden or 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
# encoding: utf-8 | |
# B: 96% ↑ (0:14) | |
# B: 20% ↓ (0:30) | |
# B: 100% ↔ | |
acpi_output = %x[/usr/bin/acpi].split(' ').map{|i| i.gsub(',', '')} | |
status_symbols = { | |
'Unknown' => '↔', | |
'Full' => '↔', | |
'Charging' => '↑', | |
'Discharging' => '↓' | |
} | |
level_colors = { | |
'red' => (0..9), | |
'yellow' => (10..19), | |
'green' => (20..100) | |
} | |
output_percentage = acpi_output[3] | |
battery_level = case output_percentage.delete('%').to_i | |
when level_colors['red'] | |
"<fc=#FF0000>#{output_percentage}</fc>" | |
when level_colors['yellow'] | |
"<fc=#FFFF00>#{output_percentage}</fc>" | |
when level_colors['green'] | |
"<fc=#00FF00>#{output_percentage}</fc>" | |
else | |
"<fc=#00FF00>#{output_percentage}</fc>" | |
end | |
symbol = status_symbols[acpi_output[2]] | |
time = if acpi_output[4] | |
time_orig = acpi_output[4].split(':') | |
"(#{time_orig[0]}:#{time_orig[1]})" | |
else | |
"(F)" | |
end | |
puts "Bat: #{battery_level} #{symbol} #{time}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment