Sha256: 88e498fd2627d7a819c5b8829bab438f293df64076a41ed7e3aa7cd2f9114277

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

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

Flyrb.equip(:clipboard)

module Flyrb
  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 Flyrb::Google
end if Object.const_defined? :IRB

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flyrb-1.0.0.c lib/flyrb/google.rb
flyrb-1.0.0.b lib/flyrb/google.rb
flyrb-1.0.0.a lib/flyrb/google.rb