Class: Launchy::Application::Browser
- Inherits:
-
Launchy::Application
- Object
- Launchy::Application
- Launchy::Application::Browser
- Defined in:
- lib/launchy/applications/browser.rb
Overview
The class handling the browser application and all of its schemes
Instance Attribute Summary
Attributes inherited from Launchy::Application
Class Method Summary collapse
Instance Method Summary collapse
-
#app_list ⇒ Object
use a call back mechanism to get the right app_list that is decided by the host_os_family class.
-
#browser_cmdline ⇒ Object
Get the full commandline of what we are going to add the uri to.
- #browser_env ⇒ Object
- #cmd_and_args(uri, _options = {}) ⇒ Object
- #cygwin_app_list ⇒ Object
-
#darwin_app_list ⇒ Object
hardcode this to open?.
- #nix_app_list ⇒ Object
-
#open(uri, options = {}) ⇒ Object
final assembly of the command and do %s substitution www.catb.org/~esr/BROWSER/index.html.
-
#windows_app_list ⇒ Object
The escaped \ is necessary so that when shellsplit is done later, the “launchy”, with quotes, goes through to the commandline, since that.
Methods inherited from Launchy::Application
find_executable, #find_executable, for_name, handling, has_name?, #initialize, #run
Methods included from DescendantTracker
#children, #find_child, #inherited
Constructor Details
This class inherits a constructor from Launchy::Application
Class Method Details
.handles?(uri) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/launchy/applications/browser.rb', line 13 def self.handles?(uri) return true if schemes.include?(uri.scheme) true if File.exist?(uri.path) end |
.schemes ⇒ Object
9 10 11 |
# File 'lib/launchy/applications/browser.rb', line 9 def self.schemes %w[http https ftp file] end |
Instance Method Details
#app_list ⇒ Object
use a call back mechanism to get the right app_list that is decided by the host_os_family class.
42 43 44 |
# File 'lib/launchy/applications/browser.rb', line 42 def app_list host_os_family.app_list(self) end |
#browser_cmdline ⇒ Object
Get the full commandline of what we are going to add the uri to
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/launchy/applications/browser.rb', line 56 def browser_cmdline browser_env.each do |p| Launchy.log "#{self.class.name} : possibility from BROWSER environment variable : #{p}" end app_list.each do |p| Launchy.log "#{self.class.name} : possibility from app_list : #{p}" end possibilities = (browser_env + app_list).flatten if (browser = possibilities.shift) Launchy.log "#{self.class.name} : Using browser value '#{browser}'" return browser end raise Launchy::CommandNotFoundError, "Unable to find a browser command. If this is unexpected, #{Launchy.}" end |
#browser_env ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/launchy/applications/browser.rb', line 46 def browser_env return [] unless ENV["BROWSER"] browser_env = ENV["BROWSER"].split(File::PATH_SEPARATOR) browser_env.flatten! browser_env.delete_if { |b| b.nil? || b.strip.empty? } browser_env end |
#cmd_and_args(uri, _options = {}) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/launchy/applications/browser.rb', line 74 def cmd_and_args(uri, = {}) cmd = browser_cmdline.to_s args = [uri.to_s] cmd.gsub!("%s", args.shift) if cmd.include?("%s") [cmd, args] end |
#cygwin_app_list ⇒ Object
25 26 27 |
# File 'lib/launchy/applications/browser.rb', line 25 def cygwin_app_list ['cmd /C start \\"launchy\\" /b'] end |
#darwin_app_list ⇒ Object
hardcode this to open?
30 31 32 |
# File 'lib/launchy/applications/browser.rb', line 30 def darwin_app_list [find_executable("open")] end |
#nix_app_list ⇒ Object
34 35 36 37 38 |
# File 'lib/launchy/applications/browser.rb', line 34 def nix_app_list nix_de = Launchy::Detect::NixDesktopEnvironment.detect list = nix_de.browsers list.find_all(&:valid?) end |
#open(uri, options = {}) ⇒ Object
final assembly of the command and do %s substitution www.catb.org/~esr/BROWSER/index.html
83 84 85 86 |
# File 'lib/launchy/applications/browser.rb', line 83 def open(uri, = {}) cmd, args = cmd_and_args(uri, ) run(cmd, args) end |
#windows_app_list ⇒ Object
The escaped \ is necessary so that when shellsplit is done later, the “launchy”, with quotes, goes through to the commandline, since that
21 22 23 |
# File 'lib/launchy/applications/browser.rb', line 21 def windows_app_list ['start \\"launchy\\" /b'] end |