Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add tmux notifier #331

Merged
merged 4 commits into from

3 participants

@royvandewater

The Tmux notifier changes the background color of the Tmux window status bar that is currently running Guard.

@thibaudgg thibaudgg commented on the diff
@@ -3,7 +3,7 @@ source :rubygems
gemspec
gem 'rake'
-gem 'listen', :github => 'guard/listen'
+gem 'listen', :git => 'http://github.com/guard/listen.git' #:github => 'guard/listen'
@thibaudgg Owner

Do you not use Bundler 1.2.x? Anyway please don't change that :)

Crap, I was trying to be so careful not to check that in. We're behind a corporate firewall, so we can't use the git protocol :-(

@netzpirat Owner

Ha, and I forgot it also when I merged it g

@thibaudgg Owner

Ok no worries @royvandewater, thanks to @netzpirat for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@thibaudgg
Owner

@netzpirat you are the notifier guy :) Ok for you?

@netzpirat
Owner

Oh how I'm happy being the Notifier guy and not the Windows guy :wink2: Looks fine, will push the merge soon.

@netzpirat netzpirat merged commit bd213c8 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 25, 2012
  1. Add tmux notifier

    Roy van de Water authored Integrum User committed
  2. Fix notifier spec to stub out the tmux add_notifier call

    Roy van de Water authored Integrum User committed
Commits on Sep 26, 2012
  1. Allow default colors to be overwritten in tmux notifier

    Roy van de Water authored Integrum User committed
  2. Change tmux status bar to status-left-bg

    Roy van de Water authored Integrum User committed
This page is out of date. Refresh to see the latest.
View
2  Gemfile
@@ -3,7 +3,7 @@ source :rubygems
gemspec
gem 'rake'
-gem 'listen', :github => 'guard/listen'
+gem 'listen', :git => 'http://github.com/guard/listen.git' #:github => 'guard/listen'
@thibaudgg Owner

Do you not use Bundler 1.2.x? Anyway please don't change that :)

Crap, I was trying to be so careful not to check that in. We're behind a corporate firewall, so we can't use the git protocol :-(

@netzpirat Owner

Ha, and I forgot it also when I merged it g

@thibaudgg Owner

Ok no worries @royvandewater, thanks to @netzpirat for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
# The development group will no be
# installed on Travis CI.
View
4 README.md
@@ -188,6 +188,10 @@ group :development do
end
```
+### Tmux
+
+* To use Tmux notifications, you have to start guard within a [tmux](http://tmux.sourceforge.net/) session
+
Add Guard plugins
-----------------
View
9 lib/guard/notifier.rb
@@ -14,6 +14,7 @@ module Guard
# * rb-notifu
# * emacs
# * Terminal Notifier
+ # * Tmux
#
# Please see the documentation of each notifier for more information about the requirements
# and configuration possibilities.
@@ -45,6 +46,7 @@ module Notifier
require 'guard/notifiers/rb_notifu'
require 'guard/notifiers/emacs'
require 'guard/notifiers/terminal_notifier'
+ require 'guard/notifiers/tmux'
extend self
@@ -58,7 +60,8 @@ module Notifier
[:notifysend, ::Guard::Notifier::NotifySend],
[:notifu, ::Guard::Notifier::Notifu],
[:emacs, ::Guard::Notifier::Emacs],
- [:terminal_notifier, ::Guard::Notifier::TerminalNotifier]
+ [:terminal_notifier, ::Guard::Notifier::TerminalNotifier],
+ [:tmux, ::Guard::Notifier::Tmux]
]
# Get the available notifications.
@@ -126,7 +129,7 @@ def add_notification(name, options = { }, silent = false)
return turn_off if name == :off
notifier = get_notifier_module(name)
-
+
if notifier && notifier.available?(silent)
self.notifications = notifications << { :name => name, :options => options }
true
@@ -168,7 +171,7 @@ def get_notifier_module(name)
notifier = NOTIFIERS.detect { |n| n.first == name }
notifier ? notifier.last : notifier
end
-
+
# Auto detect the available notification library. This goes through
# the list of supported notification gems and picks the first that
# is available.
View
69 lib/guard/notifiers/tmux.rb
@@ -0,0 +1,69 @@
+module Guard
+ module Notifier
+
+ # Default options for Tmux
+
+ # Changes the color of the Tmux status bar
+ #
+ # @example Add the `:tmux` notifier to your `Guardfile`
+ # notification :tmux
+ #
+ module Tmux
+ extend self
+
+ DEFAULTS = {
+ :client => 'tmux',
+ :tmux_environment => 'TMUX',
+ :success => 'green',
+ :failed => 'red',
+ :default => 'green',
+ }
+
+ # Test if currently running in a Tmux session
+ #
+ # @param [Boolean] silent true if no error messages should be shown
+ # @return [Boolean] the availability status
+ #
+ def available?(silent = false)
+ if ENV[DEFAULTS[:tmux_environment]].nil?
+ ::Guard::UI.error 'The :tmux notifier runs only on when guard is executed inside of a tmux session.' unless silent
+ false
+ else
+ true
+ end
+ end
+
+ # Show a system notification.
+ #
+ # @param [String] type the notification type. Either 'success', 'pending', 'failed' or 'notify'
+ # @param [String] title the notification title
+ # @param [String] message the notification message body
+ # @param [String] image the path to the notification image
+ # @param [Hash] options additional notification library options
+ # @option options [Boolean] sticky make the notification sticky
+ # @option options [String, Integer] priority specify an int or named key (default is 0)
+ #
+ def notify(type, title, message, image, options = { })
+ color = tmux_color type, options
+ system("#{DEFAULTS[:client]} set -g status-left-bg #{color}")
+ end
+
+ # Get the Tmux color for the notification type.
+ # You can configure your own color by overwriting the defaults.
+ #
+ # @param [String] type the notification type
+ # @return [String] the name of the emacs color
+ #
+ def tmux_color(type, options = { })
+ case type
+ when 'success'
+ options[:success] || DEFAULTS[:success]
+ when 'failed'
+ options[:failed] || DEFAULTS[:failed]
+ else
+ options[:default] || DEFAULTS[:default]
+ end
+ end
+ end
+ end
+end
View
1  spec/guard/notifier_spec.rb
@@ -39,6 +39,7 @@
Guard::Notifier.should_receive(:add_notification).with(:notifu, { }, true).and_return false
Guard::Notifier.should_receive(:add_notification).with(:emacs, { }, true).and_return false
Guard::Notifier.should_receive(:add_notification).with(:terminal_notifier, { }, true).and_return false
+ Guard::Notifier.should_receive(:add_notification).with(:tmux, { }, true).and_return false
Guard::Notifier.turn_on
end
View
76 spec/guard/notifiers/tmux_spec.rb
@@ -0,0 +1,76 @@
+require 'spec_helper'
+
+describe Guard::Notifier::Tmux do
+ before(:all) { Object.send(:remove_const, :Tmux) if defined?(::Tmux) }
+
+ before do
+ class ::Tmux
+ def self.show(options) end
+ end
+ end
+
+ after { Object.send(:remove_const, :Tmux) if defined?(::Tmux) }
+
+ describe '.available?' do
+ context "when the TMUX environment variable is set" do
+ before :each do
+ ENV['TMUX'] = 'something'
+ end
+
+ it "should return true" do
+ subject.available?.should be_true
+ end
+ end
+
+ context "when the TMUX environment variable is not set" do
+ before :each do
+ ENV['TMUX'] = nil
+ end
+
+ context 'without the silent option' do
+ it 'shows an error message when the TMUX environment variable is not set' do
+ ::Guard::UI.should_receive(:error).with "The :tmux notifier runs only on when guard is executed inside of a tmux session."
+ subject.available?
+ end
+ end
+
+ context 'with the silent option' do
+ it 'should return false' do
+ subject.available?(true).should be_false
+ end
+ end
+ end
+ end
+
+ describe '.notify' do
+ it 'should set the tmux status bar color to green on success' do
+ subject.should_receive(:system).with "tmux set -g status-left-bg green"
+
+ subject.notify('success', 'any title', 'any message', 'any image', { })
+ end
+
+ it 'should set the tmux status bar color to black on success when black is passed in as an option' do
+ subject.should_receive(:system).with "tmux set -g status-left-bg black"
+
+ subject.notify('success', 'any title', 'any message', 'any image', { :success => 'black' })
+ end
+
+ it 'should set the tmux status bar color to red on failure' do
+ subject.should_receive(:system).with "tmux set -g status-left-bg red"
+
+ subject.notify('failed', 'any title', 'any message', 'any image', { })
+ end
+
+ it 'should set the tmux status bar color to green on pending' do
+ subject.should_receive(:system).with "tmux set -g status-left-bg green"
+
+ subject.notify('pending', 'any title', 'any message', 'any image', { })
+ end
+
+ it 'should set the tmux status bar color to green on notify' do
+ subject.should_receive(:system).with "tmux set -g status-left-bg green"
+
+ subject.notify('notify', 'any title', 'any message', 'any image', { })
+ end
+ end
+end
Something went wrong with that request. Please try again.