lib/timber/cli/os_helper.rb in timber-2.1.0.rc2 vs lib/timber/cli/os_helper.rb in timber-2.1.0.rc3

- old
+ new

@@ -1,9 +1,9 @@ module Timber class CLI module OSHelper - def self.copy_to_clipboard? + def self.can_copy_to_clipboard? `which pbcopy` != "" rescue Exception false end @@ -32,22 +32,35 @@ rescue Exception false end end + def self.can_open? + begin + `which #{open_command}` != "" + rescue Exception + false + end + end + # Attemps to open a URL in the user's default browser across # the popular operating systems. def self.open(link) - if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ - system "start #{link}" - elsif RbConfig::CONFIG['host_os'] =~ /darwin/ - system "open #{link}" - elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/ - system "xdg-open #{link}" - end + `#{open_command} #{link}` true rescue Exception false end + + private + def self.open_command + if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ + "start" + elsif RbConfig::CONFIG['host_os'] =~ /darwin/ + "open" + elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/ + "xdg-open" + end + end end end end \ No newline at end of file