Skip to content

Instantly share code, notes, and snippets.

@sunny
Forked from sr/gist:25914
Created November 17, 2008 21:38
Show Gist options
  • Save sunny/25917 to your computer and use it in GitHub Desktop.
Save sunny/25917 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class String
def truncate(length = 30, truncate_string = "...")
return self if self.length <= length
short_length = length - truncate_string.length
self[0...short_length] + truncate_string
end
end
def date
Time.now.strftime('%Y/%m/%d %H:%M')
end
def mpd
mpc = `mpc`
status = mpc =~ /\[(\w+)\]/ && $1
return 'blargh' unless status
return status.to_s unless status == 'playing'
song = mpc.split("\n")[0]
song.truncate(30)
end
puts "#{date} | M: #{mpd}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment