Class: Launchy::Application
- Defined in:
- lib/gems/launchy-0.3.2/lib/launchy/application.rb
Direct Known Subclasses
Constant Summary collapse
- KNOWN_OS_FAMILIES =
[ :windows, :darwin, :nix, :cygwin ]
Class Method Summary collapse
- .application_classes ⇒ Object
- .find_application_class_for(*args) ⇒ Object
-
.find_executable(bin, *paths) ⇒ Object
mkrf did such a good job on this I had to borrow it.
- .inherited(sub_class) ⇒ Object
-
.my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration.
-
.my_os_family(test_os = my_os) ⇒ Object
detect what the current os is and return :windows, :darwin or :nix.
Instance Method Summary collapse
-
#app_list ⇒ Object
returns the list of command line application names for the current os.
-
#cygwin_app_list ⇒ Object
Cygwin uses the windows start but through an explicit execution of the cmd shell.
-
#darwin_app_list ⇒ Object
On darwin a good general default is the ‘open’ executable.
-
#find_executable(bin, *paths) ⇒ Object
find an executable in the available paths.
-
#my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration.
-
#my_os_family(test_os = my_os) ⇒ Object
detect what the current os is and return :windows, :darwin, :nix, or :cygwin.
-
#nix_desktop_environment ⇒ Object
Determine the appropriate desktop environment for *nix machine.
-
#run(cmd, *args) ⇒ Object
run the command.
-
#windows_app_list ⇒ Object
On windows a good general default is the ‘start’ Command Shell command.
Class Method Details
.application_classes ⇒ Object
12 13 14 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 12 def application_classes @application_classes ||= [] end |
.find_application_class_for(*args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 16 def find_application_class_for(*args) Launchy.log "#{self.name} : finding application classes for [#{args.join(' ')}]" application_classes.find do |klass| Launchy.log "#{self.name} : Trying #{klass.name}" if klass.handle?(*args) then true else false end end end |
.find_executable(bin, *paths) ⇒ Object
mkrf did such a good job on this I had to borrow it.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 30 def find_executable(bin,*paths) paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty? paths.each do |path| file = File.join(path,bin) if File.executable?(file) then Launchy.log "#{self.name} : found executable #{file}" return file end end Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(', ')}" return nil end |
.inherited(sub_class) ⇒ Object
9 10 11 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 9 def inherited(sub_class) application_classes << sub_class end |
.my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration
44 45 46 47 48 49 50 51 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 44 def my_os if ENV['LAUNCHY_HOST_OS'] then Launchy.log "#{self.name} : Using LAUNCHY_HOST_OS override of '#{ENV['LAUNCHY_HOST_OS']}'" return ENV['LAUNCHY_HOST_OS'] else ::Config::CONFIG['host_os'] end end |
.my_os_family(test_os = my_os) ⇒ Object
detect what the current os is and return :windows, :darwin or :nix
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 54 def my_os_family(test_os = my_os) case test_os when /mingw/i family = :windows when /mswin/i family = :windows when /windows/i family = :windows when /darwin/i family = :darwin when /mac os/i family = :darwin when /solaris/i family = :nix when /bsd/i family = :nix when /linux/i family = :nix when /aix/i family = :nix when /cygwin/i family = :cygwin else $stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug to #{Launchy::SPEC.email}" family = :unknown end end |
Instance Method Details
#app_list ⇒ Object
returns the list of command line application names for the current os. The list returned should only contain appliations or commands that actually exist on the system. The list members should have their full path to the executable.
122 123 124 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 122 def app_list @app_list ||= self.send("#{my_os_family}_app_list") end |
#cygwin_app_list ⇒ Object
Cygwin uses the windows start but through an explicit execution of the cmd shell
139 140 141 142 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 139 def cygwin_app_list Launchy.log "#{self.class.name} : Using 'cmd /C start' on windows." [ "cmd /C start" ] end |
#darwin_app_list ⇒ Object
On darwin a good general default is the ‘open’ executable.
127 128 129 130 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 127 def darwin_app_list Launchy.log "#{self.class.name} : Using 'open' application on darwin." [ find_executable('open') ] end |
#find_executable(bin, *paths) ⇒ Object
find an executable in the available paths
105 106 107 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 105 def find_executable(bin,*paths) Application.find_executable(bin,*paths) end |
#my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration
110 111 112 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 110 def my_os Application.my_os end |
#my_os_family(test_os = my_os) ⇒ Object
detect what the current os is and return :windows, :darwin, :nix, or :cygwin
115 116 117 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 115 def my_os_family(test_os = my_os) Application.my_os_family(test_os) end |
#nix_desktop_environment ⇒ Object
Determine the appropriate desktop environment for *nix machine. Currently this is linux centric. The detection is based upon the detection used by xdg-open from portland.freedesktop.org/wiki/XdgUtils
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 87 def nix_desktop_environment if not @nix_desktop_environment then @nix_desktop_environment = :generic if ENV["KDE_FULL_SESSION"] || ENV["KDE_SESSION_UID"] then @nix_desktop_environment = :kde elsif ENV["GNOME_DESKTOP_SESSION_ID"] then @nix_desktop_environment = :gnome elsif find_executable("xprop") then if %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0 then @nix_desktop_environment = :xfce end end Launchy.log "#{self.class.name} : nix_desktop_environment => '#{@nix_desktop_environment}'" end return @nix_desktop_environment end |
#run(cmd, *args) ⇒ Object
run the command
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/gems/launchy-0.3.2/lib/launchy/application.rb', line 145 def run(cmd,*args) args.unshift(cmd) cmd_line = args.join(' ') Launchy.log "#{self.class.name} : Spawning on #{my_os_family} : #{cmd_line}" if my_os_family == :windows then system cmd_line else # fork, and the child process should NOT run any exit handlers child_pid = fork do cmd_line += " > /dev/null 2>&1" system cmd_line exit! end Process.detach(child_pid) end end |