Making a Status Bar IV

After getting frustrated with conky and awesome-client in Making a Status Bar III, I wrote the following using ruby.

As an aside, to get conky working: ...or, you can just read Making a Status Bar V
 * pull conky's source
 * recompile without X11 support

Anyway...

Modify your ~/.awesomerc
statusbar "bottom" { position = "bottom" height = 0 width = 0

textbox clock { text_align = "left" align = "left" width = 100 }

textbox mpdstatus { text_align="right" align="right" }

textbox song { text_align="right" align="right" }

textbox time { text_align="right" align="right" }   }

Create an "awesome-status"
You'll need the following if you don't have it already: require 'rubygems' require 'librmpd' require 'date'
 * ruby
 * rubygems
 * librmpd
 * 1) !/usr/bin/env ruby

class MyClient Pipe = '/usr/bin/awesome-client' def writeDate date = DateTime::now writePipe("clock", date.strftime('%a %e %b %Y %H:%M')) end

def state_callback(newstate) writePipe("mpdstatus", "#{newstate} | ") end

def song_callback(newsong) song = "#{newsong.artist} | #{newsong.album} | #{newsong.title}" writePipe("song", song) end

def time_callback(elapsed, total) time = " | #{formatSeconds(elapsed)} | #{formatSeconds(total)}" writePipe("time", time) end

private def writePipe(widget, status)

# This was annoying -- I finally figured out I needed a newline to ensure the status was updated toWrite = "0 widget_tell #{widget} #{status}\n" pipe = IO.popen(Pipe, "w") pipe.write(toWrite) pipe.close end

def formatSeconds(time) minutes = time / 60 seconds = time % 60 return "%02d:%02d" % [ minutes, seconds ] end end

client = MyClient.new

mpd = MPD.new 'localhost', 6600 mpd.register_callback(client.method('state_callback'), MPD::STATE_CALLBACK) mpd.register_callback(client.method('song_callback'), MPD::CURRENT_SONG_CALLBACK) mpd.register_callback(client.method('time_callback'), MPD::TIME_CALLBACK)
 * 1) If you restart awesome, you lose some info until a "current song" event is fired.

mpd.connect(true)

while true do   client.writeDate sleep 1 end

Apply the proper permissions to "awesome-status"
$ chmod 755 awesome-status

Modify your ~/.xinitrc
awesome-status & exec awesome

Enjoy!