-
-
Save sunny/25917 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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