Permalink
Browse files

support terminal-notifier

  • Loading branch information...
1 parent 716c4ae commit 70d9c2675bd41204a6b95438e35064cf8a9b263f @jugyo committed Aug 17, 2012
Showing with 34 additions and 10 deletions.
  1. +1 −1 g.gemspec
  2. +23 −3 lib/g.rb
  3. +5 −0 lib/g/ruby_gntp.rb
  4. +5 −0 lib/g/terminal-notifier.rb
  5. +0 −6 lib/md5.rb
View
@@ -12,6 +12,6 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_runtime_dependency "ruby_gntp"
+ s.add_development_dependency "ruby_gntp"
s.add_development_dependency "rspec"
end
View
@@ -1,7 +1,11 @@
-require 'rubygems'
-require 'ruby_gntp'
+require 'pp'
module Kernel
+ def self._g_function(&block)
+ @_g_function = block if block
+ @_g_function
+ end
+
def g(*args)
messages = args.dup
@@ -15,7 +19,11 @@ def g(*args)
messages.each do |i|
text = i.is_a?(String) ? i : i.pretty_inspect
- GNTP.notify :app_name => $0, :title => 'g', :text => text
+ if Kernel._g_function
+ Kernel._g_function.call($0, 'g', text)
+ else
+ p text
+ end
end
if args.empty?
@@ -27,3 +35,15 @@ def g(*args)
end
end
end
+
+catch(:break) do
+ %w(terminal-notifier ruby_gntp).each do |lib|
+ begin
+ require lib
+ require "g/#{lib}"
+ throw :break
+ rescue LoadError
+ end
+ end
+ warn 'Please install `terminal-notifier` or `ruby_gntp`.'
+end
View
@@ -0,0 +1,5 @@
+module Kernel
+ _g_function do |app_name, title, text|
+ GNTP.notify :app_name => app_name, :title => title, :text => text
+ end
+end
@@ -0,0 +1,5 @@
+module Kernel
+ _g_function do |app_name, title, text|
+ TerminalNotifier.notify(text, :title => title)
+ end
+end
View
@@ -1,6 +0,0 @@
-require 'digest/md5'
-module MD5
- def self.new(packet)
- Digest::MD5.new.update packet
- end
-end

0 comments on commit 70d9c26

Please sign in to comment.