Skip to content

Instantly share code, notes, and snippets.

@mxrnx
Last active February 13, 2018 13:00
Show Gist options
  • Save mxrnx/2c301acf34ce48b9fc7fba486c8ac308 to your computer and use it in GitHub Desktop.
Save mxrnx/2c301acf34ce48b9fc7fba486c8ac308 to your computer and use it in GitHub Desktop.
script to populate my status bar
#!/usr/bin/env ruby
require 'date'
def batterystatus
charging, percentage = `acpi`.match(/^Battery 0: (\w+), (\d+).*$/i).captures
blocks = (percentage.to_i / 100.0 * 10).round
char = case charging
when 'Charging'
'>'
when 'Discharging'
'<'
else
'|'
end
blocks.times.collect {char}.join('') + (10 - blocks).times.collect {'_'}.join('')
end
def timestatus
Time.now.strftime '%H:%M:%S'
end
def datestatus
Time.now.strftime '%Y-%m-%d'
end
def status
"#{batterystatus} | #{timestatus} | #{datestatus}"
end
while true do
puts status
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment