Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stahnma/498229 to your computer and use it in GitHub Desktop.
Save stahnma/498229 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Place this in your $PROJECT/.git/hooks directory
# File should be named 'commit-msg'
# Ensure you have dbus bindings for ruby installed
#
#
# Limitations:
# * Only works for Amarok so far, as that's what I use.
# * If your songs are tagged poorly, your commit message will be also.
#
require 'dbus'
def song
amarok_sbus = DBus::SessionBus.instance
begin
dbus = amarok_sbus.service("org.kde.amarok")
player = dbus.object("/Player")
player.introspect
rescue DBus::Error
# "Music player not opened."
return ""
end
player.default_iface = "org.freedesktop.MediaPlayer"
resp = ""
player.GetMetadata.each do |hash|
begin
resp = "Artist: #{hash['artist'] }\n"
resp << "Song: #{hash['title']}\n"
resp << "Album: #{hash['album']}\n"
rescue
resp = "No song playing."
end
end
return resp.to_s
end
message_file = ARGV[0]
message = File.read(message_file)
message.strip!
mesg = "\n\n\n" + song
File.open(message_file, 'a') do |f|
f.write(mesg)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment