guard 2.10.5 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/guard.rb +0 -3
- data/lib/guard/aruba_adapter.rb +6 -6
- data/lib/guard/cli.rb +5 -0
- data/lib/guard/commander.rb +1 -1
- data/lib/guard/commands/all.rb +2 -2
- data/lib/guard/commands/notification.rb +1 -1
- data/lib/guard/commands/reload.rb +2 -2
- data/lib/guard/commands/show.rb +1 -1
- data/lib/guard/deprecated/evaluator.rb +3 -1
- data/lib/guard/deprecated/guard.rb +57 -2
- data/lib/guard/dsl.rb +2 -3
- data/lib/guard/dsl_describer.rb +8 -20
- data/lib/guard/guardfile/evaluator.rb +5 -5
- data/lib/guard/guardfile/generator.rb +3 -3
- data/lib/guard/internals/debugging.rb +5 -5
- data/lib/guard/internals/session.rb +19 -8
- data/lib/guard/internals/state.rb +0 -13
- data/lib/guard/jobs/pry_wrapper.rb +5 -5
- data/lib/guard/notifier.rb +43 -219
- data/lib/guard/plugin_util.rb +1 -1
- data/lib/guard/terminal.rb +3 -2
- data/lib/guard/ui.rb +7 -2
- data/lib/guard/version.rb +1 -1
- data/lib/guard/watcher.rb +3 -3
- metadata +30 -15
- data/lib/guard/notifier/detected.rb +0 -87
- data/lib/guard/notifiers/base.rb +0 -221
- data/lib/guard/notifiers/emacs.rb +0 -99
- data/lib/guard/notifiers/file_notifier.rb +0 -54
- data/lib/guard/notifiers/gntp.rb +0 -111
- data/lib/guard/notifiers/growl.rb +0 -104
- data/lib/guard/notifiers/libnotify.rb +0 -86
- data/lib/guard/notifiers/notifysend.rb +0 -110
- data/lib/guard/notifiers/rb_notifu.rb +0 -100
- data/lib/guard/notifiers/terminal_notifier.rb +0 -90
- data/lib/guard/notifiers/terminal_title.rb +0 -31
- data/lib/guard/notifiers/tmux.rb +0 -335
- data/lib/guard/sheller.rb +0 -143
@@ -1,90 +0,0 @@
|
|
1
|
-
require "guard/notifiers/base"
|
2
|
-
|
3
|
-
module Guard
|
4
|
-
module Notifier
|
5
|
-
# System notifications using the
|
6
|
-
#
|
7
|
-
# [terminal-notifier](https://github.com/Springest/terminal-notifier-guard)
|
8
|
-
#
|
9
|
-
# gem.
|
10
|
-
#
|
11
|
-
# This gem is available for OS X 10.8 Mountain Lion and sends notifications
|
12
|
-
# to the OS X notification center.
|
13
|
-
#
|
14
|
-
# @example Add the `terminal-notifier-guard` gem to your `Gemfile`
|
15
|
-
# group :development
|
16
|
-
# gem 'terminal-notifier-guard'
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# @example Add the `:terminal_notifier` notifier to your `Guardfile`
|
20
|
-
# notification :terminal_notifier
|
21
|
-
#
|
22
|
-
# @example Display application name as subtitle
|
23
|
-
# notification :terminal_notifier, subtitle: “MyApp"
|
24
|
-
#
|
25
|
-
# @example Use iTerm2 for notifications
|
26
|
-
# notification :terminal_notifier, activate: "com.googlecode.iterm2"
|
27
|
-
#
|
28
|
-
class TerminalNotifier < Base
|
29
|
-
ERROR_TERMINAL_NOTIFIER_ONLY_OSX10 = "The :terminal_notifier only runs"\
|
30
|
-
" on Mac OS X 10.8 and later."
|
31
|
-
|
32
|
-
def self.supported_hosts
|
33
|
-
%w(darwin)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.gem_name
|
37
|
-
"terminal-notifier-guard"
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.available?(opts = {})
|
41
|
-
super && require_gem_safely(opts) && _register!(opts)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Shows a system notification.
|
45
|
-
#
|
46
|
-
# @param [String] message the notification message body
|
47
|
-
# @param [Hash] opts additional notification library options
|
48
|
-
# @option opts [String] type the notification type. Either 'success',
|
49
|
-
# 'pending', 'failed' or 'notify'
|
50
|
-
# @option opts [String] title the notification title
|
51
|
-
# @option opts [String] image the path to the notification image (ignored)
|
52
|
-
# @option opts [String] app_name name of your app
|
53
|
-
# @option opts [String] execute a command
|
54
|
-
# @option opts [String] activate an app bundle
|
55
|
-
# @option opts [String] open some url or file
|
56
|
-
#
|
57
|
-
def notify(message, opts = {})
|
58
|
-
title = opts[:title] || options[:title]
|
59
|
-
super
|
60
|
-
self.class.require_gem_safely
|
61
|
-
|
62
|
-
opts.delete(:image)
|
63
|
-
opts[:title] = title || [
|
64
|
-
opts.delete(:app_name) { "Guard" }, opts[:type].downcase.capitalize
|
65
|
-
].join(" ")
|
66
|
-
|
67
|
-
::TerminalNotifier::Guard.execute(false, opts.merge(message: message))
|
68
|
-
end
|
69
|
-
|
70
|
-
# @private
|
71
|
-
#
|
72
|
-
# Detects if the terminal-notifier-guard gem is available and if not,
|
73
|
-
# displays an error message unless `opts[:silent]` is true.
|
74
|
-
#
|
75
|
-
# @return [Boolean] whether or not the terminal-notifier-guard gem is
|
76
|
-
# available
|
77
|
-
#
|
78
|
-
def self._register!(opts)
|
79
|
-
if ::TerminalNotifier::Guard.available?
|
80
|
-
true
|
81
|
-
else
|
82
|
-
unless opts[:silent]
|
83
|
-
UI.error UI::ERROR_TERMINAL_NOTIFIER_ONLY_OSX10
|
84
|
-
end
|
85
|
-
false
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require "guard/notifiers/base"
|
2
|
-
|
3
|
-
module Guard
|
4
|
-
module Notifier
|
5
|
-
# Shows system notifications in the terminal title bar.
|
6
|
-
#
|
7
|
-
class TerminalTitle < Base
|
8
|
-
# Shows a system notification.
|
9
|
-
#
|
10
|
-
# @param [Hash] opts additional notification library options
|
11
|
-
# @option opts [String] message the notification message body
|
12
|
-
# @option opts [String] type the notification type. Either 'success',
|
13
|
-
# 'pending', 'failed' or 'notify'
|
14
|
-
# @option opts [String] title the notification title
|
15
|
-
#
|
16
|
-
def notify(message, opts = {})
|
17
|
-
super
|
18
|
-
|
19
|
-
first_line = message.sub(/^\n/, "").sub(/\n.*/m, "")
|
20
|
-
|
21
|
-
STDOUT.puts "\e]2;[#{ opts[:title] }] #{ first_line }\a"
|
22
|
-
end
|
23
|
-
|
24
|
-
# Clears the terminal title
|
25
|
-
#
|
26
|
-
def self.turn_off
|
27
|
-
STDOUT.puts "\e]2;\a"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/guard/notifiers/tmux.rb
DELETED
@@ -1,335 +0,0 @@
|
|
1
|
-
require "guard/notifiers/base"
|
2
|
-
require "guard/sheller"
|
3
|
-
|
4
|
-
module Guard
|
5
|
-
module Notifier
|
6
|
-
# Changes the color of the Tmux status bar and optionally
|
7
|
-
# shows messages in the status bar.
|
8
|
-
#
|
9
|
-
# @example Add the `:tmux` notifier to your `Guardfile`
|
10
|
-
# notification :tmux
|
11
|
-
#
|
12
|
-
# @example Enable text messages
|
13
|
-
# notification :tmux, display_message: true
|
14
|
-
#
|
15
|
-
# @example Customize the tmux status colored for notifications
|
16
|
-
# notification :tmux, color_location: 'status-right-bg'
|
17
|
-
#
|
18
|
-
class Tmux < Base
|
19
|
-
@@session = nil
|
20
|
-
|
21
|
-
# Default options for the tmux notifications.
|
22
|
-
class Defaults
|
23
|
-
DEFAULTS = {
|
24
|
-
tmux_environment: "TMUX",
|
25
|
-
success: "green",
|
26
|
-
failed: "red",
|
27
|
-
pending: "yellow",
|
28
|
-
default: "green",
|
29
|
-
timeout: 5,
|
30
|
-
display_message: false,
|
31
|
-
default_message_format: "%s - %s",
|
32
|
-
default_message_color: "white",
|
33
|
-
display_on_all_clients: false,
|
34
|
-
display_title: false,
|
35
|
-
default_title_format: "%s - %s",
|
36
|
-
line_separator: " - ",
|
37
|
-
change_color: true,
|
38
|
-
color_location: "status-left-bg"
|
39
|
-
}
|
40
|
-
|
41
|
-
def self.option(opts, name)
|
42
|
-
opts.fetch(name, DEFAULTS[name])
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.[](name)
|
46
|
-
DEFAULTS[name]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class Client
|
51
|
-
CLIENT = "tmux"
|
52
|
-
class << self
|
53
|
-
def version
|
54
|
-
Float(_capture("-V")[/\d+\.\d+/])
|
55
|
-
end
|
56
|
-
|
57
|
-
def clients
|
58
|
-
ttys = _capture("list-clients", "-F", "'\#{client_tty}'")
|
59
|
-
ttys = ttys.split(/\n/)
|
60
|
-
|
61
|
-
# if user is running 'tmux -C' remove this client from list
|
62
|
-
ttys.delete("(null)")
|
63
|
-
ttys
|
64
|
-
end
|
65
|
-
|
66
|
-
def set(client, key, value)
|
67
|
-
case client
|
68
|
-
when :all, true
|
69
|
-
# call ourself
|
70
|
-
clients.each { |cl| Client.set(cl, key, value) }
|
71
|
-
else
|
72
|
-
args = client ? ["-t", client.strip] : nil
|
73
|
-
_run("set", "-q", *args, key, value)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def display(client, message)
|
78
|
-
case client
|
79
|
-
when :all, true
|
80
|
-
# call ourself
|
81
|
-
clients.each { |cl| Client.display(cl, message) }
|
82
|
-
else
|
83
|
-
args += ["-c", client.strip] if client
|
84
|
-
_run("display", *args, message)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def unset(client, key, value)
|
89
|
-
return set(client, key, value) if value
|
90
|
-
args = client ? ["-t", client.strip] : []
|
91
|
-
_run("set", "-q", "-u", *args, key)
|
92
|
-
end
|
93
|
-
|
94
|
-
def parse_options(client)
|
95
|
-
output = _capture("show", "-t", client)
|
96
|
-
Hash[output.lines.map { |line| _parse_option(line) }]
|
97
|
-
end
|
98
|
-
|
99
|
-
def _parse_option(line)
|
100
|
-
line.partition(" ").map(&:strip).reject(&:empty?)
|
101
|
-
end
|
102
|
-
|
103
|
-
def _capture(*args)
|
104
|
-
Sheller.stdout(([CLIENT] + args).join(" "))
|
105
|
-
end
|
106
|
-
|
107
|
-
def _run(*args)
|
108
|
-
Sheller.run(([CLIENT] + args).join(" "))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class Session
|
114
|
-
def initialize(_tmux)
|
115
|
-
@options_store = {}
|
116
|
-
|
117
|
-
Client.clients.each do |client|
|
118
|
-
@options_store[client] = {
|
119
|
-
"status-left-bg" => nil,
|
120
|
-
"status-right-bg" => nil,
|
121
|
-
"status-left-fg" => nil,
|
122
|
-
"status-right-fg" => nil,
|
123
|
-
"message-bg" => nil,
|
124
|
-
"message-fg" => nil,
|
125
|
-
"display-time" => nil
|
126
|
-
}.merge(Client.parse_options(client))
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def close
|
131
|
-
@options_store.each do |client, options|
|
132
|
-
options.each do |key, value|
|
133
|
-
Client.unset(client, key, value)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
@options_store = nil
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
class Error < RuntimeError
|
141
|
-
end
|
142
|
-
|
143
|
-
ERROR_NOT_INSIDE_TMUX = "The :tmux notifier runs only on when Guard"\
|
144
|
-
" is executed inside of a tmux session."
|
145
|
-
|
146
|
-
ERROR_ANCIENT_TMUX = "Your tmux version is way too old!"
|
147
|
-
|
148
|
-
def self.available?(opts = {})
|
149
|
-
return unless super
|
150
|
-
|
151
|
-
fail "PREVIOUS TMUX SESSION NOT CLEARED!" if @@session || nil
|
152
|
-
|
153
|
-
var_name = Defaults.option(opts, :tmux_environment)
|
154
|
-
fail Error, ERROR_NOT_INSIDE_TMUX unless ENV.key?(var_name)
|
155
|
-
|
156
|
-
version = Client.version
|
157
|
-
fail Error, format(ERROR_ANCIENT_TMUX, version) if version < 1.7
|
158
|
-
|
159
|
-
true
|
160
|
-
rescue Error => e
|
161
|
-
::Guard::UI.error e.message unless opts[:silent]
|
162
|
-
false
|
163
|
-
end
|
164
|
-
|
165
|
-
# Shows a system notification.
|
166
|
-
#
|
167
|
-
# By default, the Tmux notifier only makes
|
168
|
-
# use of a color based notification, changing the background color of the
|
169
|
-
# `color_location` to the color defined in either the `success`,
|
170
|
-
# `failed`, `pending` or `default`, depending on the notification type.
|
171
|
-
#
|
172
|
-
# You may enable an extra explicit message by setting `display_message`
|
173
|
-
# to true, and may further disable the colorization by setting
|
174
|
-
# `change_color` to false.
|
175
|
-
#
|
176
|
-
# @param [String] message the notification message
|
177
|
-
# @param [Hash] options additional notification library options
|
178
|
-
# @option options [String] type the notification type. Either 'success',
|
179
|
-
# 'pending', 'failed' or 'notify'
|
180
|
-
# @option options [String] message the notification message body
|
181
|
-
# @option options [String] image the path to the notification image
|
182
|
-
# @option options [Boolean] change_color whether to show a color
|
183
|
-
# notification
|
184
|
-
# @option options [String,Array] color_location the location where to draw
|
185
|
-
# the color notification
|
186
|
-
# @option options [Boolean] display_message whether to display a message
|
187
|
-
# or not
|
188
|
-
# @option options [Boolean] display_on_all_clients whether to display a
|
189
|
-
# message on all tmux clients or not
|
190
|
-
#
|
191
|
-
def notify(message, options = {})
|
192
|
-
super
|
193
|
-
options.delete(:image)
|
194
|
-
|
195
|
-
change_color = Defaults.option(options, :change_color)
|
196
|
-
locations = Array(Defaults.option(options, :color_location))
|
197
|
-
display_the_title = Defaults.option(options, :display_title)
|
198
|
-
display_message = Defaults.option(options, :display_message)
|
199
|
-
type = options.delete(:type).to_s
|
200
|
-
title = options.delete(:title)
|
201
|
-
|
202
|
-
if change_color
|
203
|
-
color = tmux_color(type, options)
|
204
|
-
locations.each { |location| Client.set(_all?, location, color) }
|
205
|
-
end
|
206
|
-
|
207
|
-
display_title(type, title, message, options) if display_the_title
|
208
|
-
|
209
|
-
return unless display_message
|
210
|
-
display_message(type, title, message, options)
|
211
|
-
end
|
212
|
-
|
213
|
-
# Displays a message in the title bar of the terminal.
|
214
|
-
#
|
215
|
-
# @param [String] title the notification title
|
216
|
-
# @param [String] message the notification message body
|
217
|
-
# @param [Hash] options additional notification library options
|
218
|
-
# @option options [String] success_message_format a string to use as
|
219
|
-
# formatter for the success message.
|
220
|
-
# @option options [String] failed_message_format a string to use as
|
221
|
-
# formatter for the failed message.
|
222
|
-
# @option options [String] pending_message_format a string to use as
|
223
|
-
# formatter for the pending message.
|
224
|
-
# @option options [String] default_message_format a string to use as
|
225
|
-
# formatter when no format per type is defined.
|
226
|
-
#
|
227
|
-
def display_title(type, title, message, options = {})
|
228
|
-
format = "#{type}_title_format".to_sym
|
229
|
-
default_title_format = Defaults.option(options, :default_title_format)
|
230
|
-
title_format = options.fetch(format, default_title_format)
|
231
|
-
teaser_message = message.split("\n").first
|
232
|
-
display_title = title_format % [title, teaser_message]
|
233
|
-
|
234
|
-
Client.set(_all?, "set-titles-string", "'#{display_title}'")
|
235
|
-
end
|
236
|
-
|
237
|
-
# Displays a message in the status bar of tmux.
|
238
|
-
#
|
239
|
-
# @param [String] type the notification type. Either 'success',
|
240
|
-
# 'pending', 'failed' or 'notify'
|
241
|
-
# @param [String] title the notification title
|
242
|
-
# @param [String] message the notification message body
|
243
|
-
# @param [Hash] options additional notification library options
|
244
|
-
# @option options [Integer] timeout the amount of seconds to show the
|
245
|
-
# message in the status bar
|
246
|
-
# @option options [String] success_message_format a string to use as
|
247
|
-
# formatter for the success message.
|
248
|
-
# @option options [String] failed_message_format a string to use as
|
249
|
-
# formatter for the failed message.
|
250
|
-
# @option options [String] pending_message_format a string to use as
|
251
|
-
# formatter for the pending message.
|
252
|
-
# @option options [String] default_message_format a string to use as
|
253
|
-
# formatter when no format per type is defined.
|
254
|
-
# @option options [String] success_message_color the success notification
|
255
|
-
# foreground color name.
|
256
|
-
# @option options [String] failed_message_color the failed notification
|
257
|
-
# foreground color name.
|
258
|
-
# @option options [String] pending_message_color the pending notification
|
259
|
-
# foreground color name.
|
260
|
-
# @option options [String] default_message_color a notification
|
261
|
-
# foreground color to use when no color per type is defined.
|
262
|
-
# @option options [String] line_separator a string to use instead of a
|
263
|
-
# line-break.
|
264
|
-
#
|
265
|
-
def display_message(type, title, message, opts = {})
|
266
|
-
default_format = Defaults.option(opts, :default_message_format)
|
267
|
-
default_color = Defaults.option(opts, :default_message_color)
|
268
|
-
display_time = Defaults.option(opts, :timeout)
|
269
|
-
separator = Defaults.option(opts, :line_separator)
|
270
|
-
|
271
|
-
format = "#{type}_message_format".to_sym
|
272
|
-
message_format = opts.fetch(format, default_format)
|
273
|
-
|
274
|
-
color = "#{type}_message_color".to_sym
|
275
|
-
message_color = opts.fetch(color, default_color)
|
276
|
-
|
277
|
-
color = tmux_color(type, opts)
|
278
|
-
formatted_message = message.split("\n").join(separator)
|
279
|
-
display_message = message_format % [title, formatted_message]
|
280
|
-
|
281
|
-
Client.set(_all?, "display-time", display_time * 1000)
|
282
|
-
Client.set(_all?, "message-fg", message_color)
|
283
|
-
Client.set(_all?, "message-bg", color)
|
284
|
-
Client.display(_all?, "'#{display_message}'")
|
285
|
-
end
|
286
|
-
|
287
|
-
# Get the Tmux color for the notification type.
|
288
|
-
# You can configure your own color by overwriting the defaults.
|
289
|
-
#
|
290
|
-
# @param [String] type the notification type
|
291
|
-
# @return [String] the name of the emacs color
|
292
|
-
#
|
293
|
-
def tmux_color(type, opts = {})
|
294
|
-
type = type.to_sym
|
295
|
-
opts[type] || Defaults[type] || Defaults.option(opts, :default)
|
296
|
-
end
|
297
|
-
|
298
|
-
# Notification starting, save the current Tmux settings
|
299
|
-
# and quiet the Tmux output.
|
300
|
-
#
|
301
|
-
def self.turn_on
|
302
|
-
_start_session
|
303
|
-
end
|
304
|
-
|
305
|
-
# Notification stopping. Restore the previous Tmux state
|
306
|
-
# if available (existing options are restored, new options
|
307
|
-
# are unset) and unquiet the Tmux output.
|
308
|
-
#
|
309
|
-
def self.turn_off
|
310
|
-
_end_session
|
311
|
-
end
|
312
|
-
|
313
|
-
private
|
314
|
-
|
315
|
-
def self._start_session
|
316
|
-
fail "Already turned on!" if @@session
|
317
|
-
@@session = Session.new(self)
|
318
|
-
end
|
319
|
-
|
320
|
-
def self._end_session
|
321
|
-
fail "Already turned off!" unless @@session || nil
|
322
|
-
@@session.close
|
323
|
-
@@session = nil
|
324
|
-
end
|
325
|
-
|
326
|
-
def self._session
|
327
|
-
@@session
|
328
|
-
end
|
329
|
-
|
330
|
-
def _all?
|
331
|
-
Defaults.option(options, :display_on_all_clients)
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|