Last active
February 13, 2018 13:00
-
-
Save mxrnx/2c301acf34ce48b9fc7fba486c8ac308 to your computer and use it in GitHub Desktop.
script to populate my status bar
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
#!/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