Module: Nimbu::Helpers::System
- Included in:
- Nimbu::Helpers, Nimbu::Helpers
- Defined in:
- lib/nimbu/helpers.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
- #tmp_dir ⇒ Object
-
#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’]
500 501 502 503 504 505 506 507 508 |
# File 'lib/nimbu/helpers.rb', line 500 def browser_launcher browser = ENV['BROWSER'] || ( osx? ? 'open' : windows? ? %w[cmd /c 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.
539 540 541 |
# File 'lib/nimbu/helpers.rb', line 539 def command?(name) !which(name).nil? end |
#osx? ⇒ Boolean
510 511 512 513 |
# File 'lib/nimbu/helpers.rb', line 510 def osx? require 'rbconfig' RbConfig::CONFIG['host_os'].to_s.include?('darwin') end |
#tmp_dir ⇒ Object
543 544 545 |
# File 'lib/nimbu/helpers.rb', line 543 def tmp_dir ENV['TMPDIR'] || ENV['TEMP'] || '/tmp' end |
#which(cmd) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
which('ruby') #=> /usr/bin/ruby
523 524 525 526 527 528 529 530 531 532 |
# File 'lib/nimbu/helpers.rb', line 523 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
515 516 517 518 |
# File 'lib/nimbu/helpers.rb', line 515 def windows? require 'rbconfig' RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/ end |