Created
March 6, 2010 21:52
-
-
Save jarib/323967 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 | |
require "rubygems" | |
require "libnotify" | |
require "daemons" | |
class IrssiNotifier | |
def initialize(host, tail_script, opts = {}) | |
@host = host | |
@script = tail_script | |
@options = opts | |
end | |
def run | |
puts "Launched @ #{Time.now}" | |
daemonize if @options[:daemonize] | |
at_exit { exit_hook } | |
tail | |
end | |
private | |
def notify(line) | |
puts "notify: #{line}" | |
show "hilight", line | |
end | |
def tail | |
IO.popen("ssh #{@host} '#{@script}'") do |io| | |
io.each { |line| notify line } | |
end | |
end | |
def exit_hook | |
show "#{self.class} exiting", "pid: #{Process.pid}" | |
rescue => e | |
$stderr.puts e | |
end | |
def show(summary, body, timeout = 10) | |
Libnotify.show :summary => summary, :body => body, :timeout => timeout | |
end | |
def daemonize | |
Daemons.daemonize | |
end | |
end | |
if __FILE__ == $0 | |
IrssiNotifier.new( | |
"linode", | |
'~/.irssi/scripts/notify-tail.sh', | |
:daemonize => ARGV.include?("-d") | |
).run | |
end | |
__END__ | |
#!/bin/sh | |
# | |
# notify-tail.sh | |
# | |
log=~/.irssi/fnotify | |
rm $log/ | |
touch $log | |
tail -F $log | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment