Sha256: f2c3971ef9b8937b41cae2694a753a68bf485fee0bfe28d454d73cfd761f1ed7

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

#!/usr/bin/env ruby
%w{rubygems platform cgi}.each {|library| require library}

UtilityBelt.equip(:clipboard)

module UtilityBelt
  module Google
    def google(search_term = nil)
      search_term ||= Clipboard.read if Clipboard.available?
      if search_term.empty?
        puts "Usage: google search_term_without_spaces           (Unix command line only)"
        puts "       google 'search term with spaces'            (Unix or IRB)"
        puts "       google                                      (Unix or IRB)"
        puts "              (if invoking without args, must have text in clipboard)"
      else
        url = "http://google.com/search?q=#{CGI.escape(search_term)}"
        case Platform::IMPL
        when :macosx
          Kernel.system("open #{url}")
        when :windows
          Kernel.system("start #{url}")
        #when :linux
        else
          puts "Sorry, don't know how to open an URL from the command line on your platform"
        end
      end
    end
  end
end

class Object
  include UtilityBelt::Google
end if Object.const_defined? :IRB

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
mguterl-utility_belt-1.0.7 lib/utility_belt/google.rb
rwilcox-utility_belt-1.0.7 lib/utility_belt/google.rb
rwilcox-utility_belt-1.0.9 lib/utility_belt/google.rb
timocratic-utility_belt-1.0.7.1 lib/utility_belt/google.rb
timocratic-utility_belt-1.0.7.2 lib/utility_belt/google.rb
timocratic-utility_belt-1.0.7.3 lib/utility_belt/google.rb
utility_belt-1.1.0 lib/utility_belt/google.rb