Permalink
Browse files

improve tmux notification to support long running shell command

  • Loading branch information...
1 parent 2b771c0 commit 79c0188d2f773ac8ae1623c52fb458db452cdf66 @linsong committed Jun 25, 2010
Showing with 27 additions and 5 deletions.
  1. +27 −5 .tmux/pipes/notification
View
@@ -1,16 +1,38 @@
#! /usr/bin/env ruby
-event_hash = {
- /^=> Ctrl-C to shutdown server/ => lambda { ["Rails started"] },
- /^(\d+ tests, \d+ assertions, \d+ failures, \d+ errors)/ => lambda { [$1, "Ruby Test"] },
-}
+#f = File.open("tmux_notification.log", "w+")
+
+CMD_HOLD_TIME_FOR_NOTIFICATION = 3
+
+sh_cmd_info = {:timestamp => 0, :cmd => ''}
def notify(msg, title="Notification")
system(%Q{/usr/local/bin/growlnotify --image ~/Desktop/mylogo.png -n "ShellNotification" -m "#{msg}" "#{title}" 2>/dev/null;})
end
+event_hash = {
+ /^=> Ctrl-C to shutdown server/ => lambda { notify("Rails started") },
+ /^(\d+ tests, \d+ assertions, \d+ failures, \d+ errors)/ => lambda { notify($1, "Ruby Test") },
+
+ /^\e\[30;47m\[\d+\]\e\[m \$(.+)\r\n/ => lambda {
+ sh_cmd_info[:timestamp] = Time.now.to_i
+ sh_cmd_info[:cmd] = $1
+ },
+ /^\e\[32mvincent@/ => lambda {
+ notify(sh_cmd_info[:cmd], "Cmd done") if sh_cmd_info[:cmd].size > 0 && (Time.now.to_i - sh_cmd_info[:timestamp] > CMD_HOLD_TIME_FOR_NOTIFICATION)
+ sh_cmd_info[:timestamp] = Time.now.to_i
+ sh_cmd_info[:cmd] = ''
+ },
+}
+
+
ARGF.each do |line|
event_hash.each_pair do |k, v|
- notify(*v.call) if line =~ k
+ begin
+ v.call if line =~ k
+ rescue Exception => e
+ #f.write(e.to_s)
+ #f.flush
+ end
end
end

0 comments on commit 79c0188

Please sign in to comment.