Skip to content

Instantly share code, notes, and snippets.

@sr
Created July 4, 2009 19:27
Show Gist options
  • Save sr/140672 to your computer and use it in GitHub Desktop.
Save sr/140672 to your computer and use it in GitHub Desktop.
my dwm status bar (in both Io and Ruby)
#!/usr/bin/env io
date := Date now asString("%Y-%m-%d %H:%M:%S")
wifi := File clone openForReading("/proc/net/wireless") readLines \
at(2) split at(5) removeAt(2) asString
mpd := method(
File clone openForReading("/home/simon/.mpd/state") foreachLine(i, line,
parts := line split(":")
if(parts at(0) == "state", state := parts at(1))
if(parts at(0) == "current", current := parts at(1) lstrip)
if(slotNames contains("current") and parts at(0) == current,
return parts at(1))
)
)
"[M: #{mpd}] [W: #{wifi}] ||| #{date}]" interpolate print
#!/usr/bin/env ruby
require "librmpd"
def date
Time.now.strftime("%Y-%m-%d %H:%M")
end
def mpd
song = MPD.new.tap { |mpd| mpd.connect }.current_song
return "NA" unless song
if song.artist && song.album && song.title
"#{song.artist} - #{song.album} - #{song.title}"
else
song.file[50..song.file.size]
end
end
def battery
state = File.readlines("/proc/acpi/battery/BAT0/state").map { |line|
line.gsub(/.*:\s*/, "").chomp }
info = File.readlines("/proc/acpi/battery/BAT0/info").map { |line|
line.gsub(/.*:\s*/, "").chomp }
percentage = ((state[4].chomp("mAh").to_f /
info[2].chomp("mAh").to_f ) * 100).to_i
status = state[2]
indicator = case status
when "charged" then "="
when "charging" then "^"
when "discharging" then "v"
else ""
end
if status == "discharging" && percentage <= 10
xmessage = "xmessage -butt xmessage -buttons quit:0 -default quit -file -"
IO.popen(xmessage, "w") { |io| io << "ZOMFGWTF CRITICAL BATTERY" }
end
"#{indicator}#{percentage}%"
end
def wifi
info = File.readlines("/proc/net/wireless")
info[2][/wlan0: \d{4}\s*(\d+)\./] && $1
rescue
0
end
puts "[M: #{mpd}] | [B: #{battery}] | [W: #{wifi}] ||| #{date}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment