Created
July 29, 2010 14:20
-
-
Save stahnma/498229 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 | |
# | |
# 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