Sha256: c162e3cfe2d37a4b52ec5a81a6fdab154b2952ce63fdb3b8c6be640f3a58af07

Contents?: true

Size: 1020 Bytes

Versions: 2

Compression:

Stored size: 1020 Bytes

Contents

require 'platform'

module UtilityBelt
  class WebBrowser
    def self.open(url)
      case Platform::IMPL
        when :macosx
          Kernel.system("open #{url}")
        when :mswin
          Kernel.system("start #{url}")
        when :linux
          #figure out the prefered web browser
          #debian
          if b = File.readlink("/etc/alternatives/x-www-browser") rescue false
            launch_linux_browser(b, url)
          #gentoo maybe
          elsif b = ENV["BROWSER"]
            launch_linux_browser(b, url)
          end
        end
    end
  
    private
    def self.launch_linux_browser(browser, url)
      if /konqueror/.match browser
        cmd = "dcop `dcop konq* | head -1` konqueror-mainwindow#1 newTab #{url}"
        Kernel.system(cmd)
      elsif /(firefox)|(swiftweasel)/.match b
        Kernel.system("#{browser} -new-tab #{url}")
      else
        Kernel.system("#{browser} #{url}")
      end
    end
  end
end

WebBrowser = UtilityBelt::WebBrowser if Object.const_defined? :IRB

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
akitaonrails-utility_belt-1.0.10 lib/utility_belt/webbrowser.rb
akitaonrails-utility_belt-1.0.11 lib/utility_belt/webbrowser.rb