Module: Hub::Context::System
- Included in:
- Hub::Context, Hub::Context
- Defined in:
- lib/hub/context.rb
Instance Method Summary collapse
-
#browser_launcher ⇒ Object
Cross-platform web browser command; respects the value set in $BROWSER.
-
#command?(name) ⇒ Boolean
Checks whether a command exists on this system in the $PATH.
- #osx? ⇒ Boolean
-
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
- #windows? ⇒ Boolean
Instance Method Details
#browser_launcher ⇒ Object
Cross-platform web browser command; respects the value set in $BROWSER.
Returns an array, e.g.: [‘open’]
422 423 424 425 426 427 428 429 430 |
# File 'lib/hub/context.rb', line 422 def browser_launcher browser = ENV['BROWSER'] || ( osx? ? 'open' : windows? ? 'start' : %w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm } ) abort "Please set $BROWSER to a web launcher to use this command." unless browser Array(browser) end |
#command?(name) ⇒ Boolean
Checks whether a command exists on this system in the $PATH.
name - The String name of the command to check for.
Returns a Boolean.
461 462 463 |
# File 'lib/hub/context.rb', line 461 def command?(name) !which(name).nil? end |
#osx? ⇒ Boolean
432 433 434 435 |
# File 'lib/hub/context.rb', line 432 def osx? require 'rbconfig' RbConfig::CONFIG['host_os'].to_s.include?('darwin') end |
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
which('ruby') #=> /usr/bin/ruby
445 446 447 448 449 450 451 452 453 454 |
# File 'lib/hub/context.rb', line 445 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = "#{path}/#{cmd}#{ext}" return exe if File.executable? exe } end return nil end |
#windows? ⇒ Boolean
437 438 439 440 |
# File 'lib/hub/context.rb', line 437 def windows? require 'rbconfig' RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/ end |