Permalink
Browse files

Merge branch 'master' into interactor/pry

  • Loading branch information...
2 parents b49a00b + 34a9057 commit b8a22e4dfd0a6b9b5130704640f4b7823e36de2d @netzpirat netzpirat committed Sep 26, 2012
View
@@ -1,3 +1,7 @@
+# Master
+
+- [#331][] Add tmux notifier. ([@royvandewater][])
+
## 1.3.3 - 20 September, 2012
- Add Guard application icon to GNTP notifier. ([@netzpirat][])
@@ -595,6 +599,7 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[#316]: https://github.com/guard/guard/issues/316
[#317]: https://github.com/guard/guard/issues/317
[#324]: https://github.com/guard/guard/issues/324
+[#331]: https://github.com/guard/guard/issues/331
[@Gazer]: https://github.com/Gazer
[@Maher4Ever]: https://github.com/Maher4Ever
[@alandipert]: https://github.com/alandipert
@@ -648,6 +653,7 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@philomory]: https://github.com/philomory
[@pirukire]: https://github.com/pirukire
[@rmm5t]: https://github.com/rmm5t
+[@royvandewater]: https://github.com/royvandewater
[@rupert654]: https://github.com/rupert654
[@rymai]: https://github.com/rymai
[@scottdavis]: https://github.com/scottdavis
@@ -668,4 +674,4 @@ The Listen integration has been supervised by [@thibaudgg][] and executed by [@M
[@waldo]: https://github.com/waldo
[@wereHamster]: https://github.com/wereHamster
[@yannlugrin]: https://github.com/yannlugrin
-[@zonque]: https://github.com/zonque
+[@zonque]: https://github.com/zonque
View
@@ -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'
# The development group will no be
# installed on Travis CI.
View
@@ -18,7 +18,7 @@ Features
* File system changes handled by our awesome [Listen](https://github.com/guard/listen) gem.
* Support for visual system notifications.
-* Huge eco-system with [more than 130](https://rubygems.org/search?query=guard-) guard plugins.
+* Huge eco-system with [more than 150](https://rubygems.org/search?query=guard-) guard plugins.
* Tested against Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest versions of JRuby & Rubinius.
Screencast
@@ -52,17 +52,52 @@ Generate an empty `Guardfile` with:
$ guard init
```
-If you are using Windows and want colors in your terminal, you'll have to add the
-[win32console](https://rubygems.org/gems/win32console) gem to your `Gemfile` and install it with Bundler:
+**It's important that you always run Guard through Bundler to avoid errors.** If you're getting sick of typing `bundle exec` all
+the time, try the [Rubygems Bundler](https://github.com/mpapis/rubygems-bundler).
+
+## OS X
+
+You may want to install the [rb-fsevent](https://github.com/thibaudgg/rb-fsevent) gem to make use of file change events
+and don't rely on polling by adding the gem to your `Gemfile` and install it with Bundler:
```ruby
group :development do
- gem 'win32console'
+ gem 'rb-fsevent', :require => false
end
```
-**It's important that you always run Guard through Bundler to avoid errors.** If you're getting sick of typing `bundle exec` all
-the time, try the [Rubygems Bundler](https://github.com/mpapis/rubygems-bundler).
+## Linux
+
+You may want to install the [rb-inotify](https://github.com/nex3/rb-inotify) gem to make use of file change events and
+don't rely on polling by adding the gem to your `Gemfile` and install it with Bundler:
+
+```ruby
+group :development do
+ gem 'rb-inotify', :require => false
+end
+```
+
+## Windows
+
+You may want to install the [wdm](https://github.com/Maher4Ever/wdm) gem to make use of file change events and don't
+rely on polling by adding the gem to your `Gemfile` and install it with Bundler:
+
+```ruby
+group :development do
+ gem 'wdm', :require => false
+end
+```
+
+Please note that you have to use at least on Ruby 1.9.2 for using WDM.
+
+If you want colors in your terminal, you'll have to add the [win32console](https://rubygems.org/gems/win32console) gem
+to your `Gemfile` and install it with Bundler:
+
+```ruby
+group :development do
+ gem 'win32console'
+end
+```
### System notifications
@@ -169,10 +204,6 @@ group :development do
end
```
-#### Emacs
-
-* Runs on any platform with Emacs + emacsclient (http://www.emacswiki.org/emacs/EmacsClient)
-
#### Terminal Notifier
* Runs on Mac OS X 10.8 only
@@ -188,6 +219,14 @@ group :development do
end
```
+#### Emacs
+
+* Runs on any platform with Emacs + emacsclient (http://www.emacswiki.org/emacs/EmacsClient)
+
+### Tmux
+
+* To use Tmux notifications, you have to start Guard within a [tmux](http://tmux.sourceforge.net/) session.
+
Add Guard plugins
-----------------
View
@@ -12,6 +12,9 @@ module Guard
# * GrowlNotify
# * Libnotify
# * rb-notifu
+ # * emacs
+ # * Terminal Notifier
+ # * Tmux
#
# Please see the documentation of each notifier for more information about the requirements
# and configuration possibilities.
@@ -43,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
@@ -56,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.
@@ -5,9 +5,9 @@ module Notifier
# Default options for EmacsClient
DEFAULTS = {
- :client => 'emacsclient',
+ :client => 'emacsclient',
:success => 'ForestGreen',
- :failed => 'Firebrick',
+ :failed => 'Firebrick',
:default => 'Black',
}
@@ -25,9 +25,9 @@ module Emacs
# @return [Boolean] the availability status
#
def available?(silent = false)
- result = `#{DEFAULTS[:client]} --eval '1' 2> /dev/null || echo 'N/A'`
+ result = `#{ DEFAULTS[:client] } --eval '1' 2> /dev/null || echo 'N/A'`
- if result.chomp! == "N/A"
+ if result.chomp! == 'N/A'
false
else
true
@@ -45,7 +45,7 @@ def available?(silent = false)
# @option options [String, Integer] priority specify an int or named key (default is 0)
#
def notify(type, title, message, image, options = { })
- system(%(#{DEFAULTS[:client]} --eval "(set-face-background 'modeline \\"#{emacs_color(type)}\\")"))
+ system(%(#{ DEFAULTS[:client] } --eval "(set-face-background 'modeline \\"#{ emacs_color(type) }\\")"))
end
# Get the Emacs color for the notification type.
@@ -41,7 +41,7 @@ def available?(silent = false)
begin
if ::GrowlNotify.application_name != 'Guard'
::GrowlNotify.config do |c|
- c.notifications = ['success', 'pending', 'failed', 'notify']
+ c.notifications = %w(success pending failed notify)
c.default_notifications = 'notify'
c.application_name = 'Guard'
end
@@ -76,7 +76,7 @@ def notifysend_urgency(type)
#
def to_command_string(command, supported, options = {})
options.reduce(command) do |cmd, (flag, value)|
- supported.include?(flag) ? cmd + " -#{flag} '#{value}'" : cmd
+ supported.include?(flag) ? cmd + " -#{ flag } '#{ value }'" : cmd
end
end
end
@@ -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
@@ -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
@@ -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

0 comments on commit b8a22e4

Please sign in to comment.