Class Launchy::Application
In: lib/launchy/application.rb
lib/launchy/application.rb
Parent: Object

Methods

Public Class methods

[Source]

    # File lib/launchy/application.rb, line 13
13:       def application_classes
14:         @application_classes ||= []
15:       end

[Source]

    # File lib/launchy/application.rb, line 13
13:       def application_classes
14:         @application_classes ||= []
15:       end

[Source]

    # File lib/launchy/application.rb, line 17
17:       def find_application_class_for(*args)
18:         Launchy.log "#{self.name} : finding application classes for [#{args.join(' ')}]"
19:         application_classes.find do |klass|
20:           Launchy.log "#{self.name} : Trying #{klass.name}"
21:           if klass.handle?(*args) then
22:             true
23:           else
24:             false
25:           end
26:         end
27:       end

[Source]

    # File lib/launchy/application.rb, line 17
17:       def find_application_class_for(*args)
18:         Launchy.log "#{self.name} : finding application classes for [#{args.join(' ')}]"
19:         application_classes.find do |klass|
20:           Launchy.log "#{self.name} : Trying #{klass.name}"
21:           if klass.handle?(*args) then
22:             true
23:           else
24:             false
25:           end
26:         end
27:       end

find an executable in the available paths mkrf did such a good job on this I had to borrow it.

[Source]

    # File lib/launchy/application.rb, line 31
31:       def find_executable(bin,*paths)
32:         paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
33:         paths.each do |path|
34:           file = File.join(path,bin)
35:           if File.executable?(file) then
36:             Launchy.log "#{self.name} : found executable #{file}"
37:             return file
38:           end
39:         end
40:         Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(', ')}"
41:         return nil
42:       end

find an executable in the available paths mkrf did such a good job on this I had to borrow it.

[Source]

    # File lib/launchy/application.rb, line 31
31:       def find_executable(bin,*paths)
32:         paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
33:         paths.each do |path|
34:           file = File.join(path,bin)
35:           if File.executable?(file) then
36:             Launchy.log "#{self.name} : found executable #{file}"
37:             return file
38:           end
39:         end
40:         Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(', ')}"
41:         return nil
42:       end

[Source]

    # File lib/launchy/application.rb, line 10
10:       def inherited(sub_class)
11:         application_classes << sub_class
12:       end

[Source]

    # File lib/launchy/application.rb, line 10
10:       def inherited(sub_class)
11:         application_classes << sub_class
12:       end

[Source]

   # File lib/launchy/application.rb, line 6
6:       def known_os_families
7:         @known_os_families ||= [ :windows, :darwin, :nix, :cygwin, :testing ]
8:       end

[Source]

   # File lib/launchy/application.rb, line 6
6:       def known_os_families
7:         @known_os_families ||= [ :windows, :darwin, :nix, :cygwin, :testing ]
8:       end

return the current ‘host_os’ string from ruby‘s configuration

[Source]

    # File lib/launchy/application.rb, line 45
45:       def my_os
46:         if ENV['LAUNCHY_HOST_OS'] then
47:           Launchy.log "#{self.name} : Using LAUNCHY_HOST_OS override of '#{ENV['LAUNCHY_HOST_OS']}'"
48:           return ENV['LAUNCHY_HOST_OS']
49:         else
50:           ::Config::CONFIG['host_os']
51:         end
52:       end

return the current ‘host_os’ string from ruby‘s configuration

[Source]

    # File lib/launchy/application.rb, line 45
45:       def my_os
46:         if ENV['LAUNCHY_HOST_OS'] then
47:           Launchy.log "#{self.name} : Using LAUNCHY_HOST_OS override of '#{ENV['LAUNCHY_HOST_OS']}'"
48:           return ENV['LAUNCHY_HOST_OS']
49:         else
50:           ::Config::CONFIG['host_os']
51:         end
52:       end

detect what the current os is and return :windows, :darwin or :nix

[Source]

    # File lib/launchy/application.rb, line 55
55:       def my_os_family(test_os = my_os)
56:         case test_os
57:         when /mingw/i
58:           family = :windows
59:         when /mswin/i
60:           family = :windows
61:         when /windows/i
62:           family = :windows
63:         when /darwin/i
64:           family = :darwin
65:         when /mac os/i
66:           family = :darwin
67:         when /solaris/i
68:           family = :nix
69:         when /bsd/i
70:           family = :nix
71:         when /linux/i
72:           family = :nix
73:         when /aix/i
74:           family = :nix
75:         when /cygwin/i
76:           family = :cygwin
77:         when /testing/i
78:           family = :testing
79:         else
80:           $stderr.puts "Unknown OS familiy for '#{test_os}'.  Please report this bug to <jeremy at hinegardner dot org>"
81:           family = :unknown
82:         end
83:       end

detect what the current os is and return :windows, :darwin or :nix

[Source]

    # File lib/launchy/application.rb, line 55
55:       def my_os_family(test_os = my_os)
56:         case test_os
57:         when /mingw/i
58:           family = :windows
59:         when /mswin/i
60:           family = :windows
61:         when /windows/i
62:           family = :windows
63:         when /darwin/i
64:           family = :darwin
65:         when /mac os/i
66:           family = :darwin
67:         when /solaris/i
68:           family = :nix
69:         when /bsd/i
70:           family = :nix
71:         when /linux/i
72:           family = :nix
73:         when /aix/i
74:           family = :nix
75:         when /cygwin/i
76:           family = :cygwin
77:         when /testing/i
78:           family = :testing
79:         else
80:           $stderr.puts "Unknown OS familiy for '#{test_os}'.  Please report this bug to <jeremy at hinegardner dot org>"
81:           family = :unknown
82:         end
83:       end

Public Instance methods

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.

[Source]

     # File lib/launchy/application.rb, line 125
125:     def app_list
126:       @app_list ||= self.send("#{my_os_family}_app_list")
127:     end

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.

[Source]

     # File lib/launchy/application.rb, line 125
125:     def app_list
126:       @app_list ||= self.send("#{my_os_family}_app_list")
127:     end

Cygwin uses the windows start but through an explicit execution of the cmd shell

[Source]

     # File lib/launchy/application.rb, line 142
142:     def cygwin_app_list
143:       Launchy.log "#{self.class.name} : Using 'cmd /C start' on windows."
144:       [ "cmd /C start" ]
145:     end

Cygwin uses the windows start but through an explicit execution of the cmd shell

[Source]

     # File lib/launchy/application.rb, line 142
142:     def cygwin_app_list
143:       Launchy.log "#{self.class.name} : Using 'cmd /C start' on windows."
144:       [ "cmd /C start" ]
145:     end

On darwin a good general default is the ‘open’ executable.

[Source]

     # File lib/launchy/application.rb, line 130
130:     def darwin_app_list
131:       Launchy.log "#{self.class.name} : Using 'open' application on darwin."
132:       [ find_executable('open') ]
133:     end

On darwin a good general default is the ‘open’ executable.

[Source]

     # File lib/launchy/application.rb, line 130
130:     def darwin_app_list
131:       Launchy.log "#{self.class.name} : Using 'open' application on darwin."
132:       [ find_executable('open') ]
133:     end

find an executable in the available paths

[Source]

     # File lib/launchy/application.rb, line 108
108:     def find_executable(bin,*paths)
109:       Application.find_executable(bin,*paths)
110:     end

find an executable in the available paths

[Source]

     # File lib/launchy/application.rb, line 108
108:     def find_executable(bin,*paths)
109:       Application.find_executable(bin,*paths)
110:     end

return the current ‘host_os’ string from ruby‘s configuration

[Source]

     # File lib/launchy/application.rb, line 113
113:     def my_os
114:       Application.my_os
115:     end

return the current ‘host_os’ string from ruby‘s configuration

[Source]

     # File lib/launchy/application.rb, line 113
113:     def my_os
114:       Application.my_os
115:     end

detect what the current os is and return :windows, :darwin, :nix, or :cygwin

[Source]

     # File lib/launchy/application.rb, line 118
118:     def my_os_family(test_os = my_os)
119:       Application.my_os_family(test_os)
120:     end

detect what the current os is and return :windows, :darwin, :nix, or :cygwin

[Source]

     # File lib/launchy/application.rb, line 118
118:     def my_os_family(test_os = my_os)
119:       Application.my_os_family(test_os)
120:     end

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

[Source]

     # File lib/launchy/application.rb, line 90
 90:     def nix_desktop_environment
 91:       if not defined? @nix_desktop_environment then
 92:         @nix_desktop_environment = :generic
 93:         if ENV["KDE_FULL_SESSION"] || ENV["KDE_SESSION_UID"] then
 94:           @nix_desktop_environment = :kde
 95:         elsif ENV["GNOME_DESKTOP_SESSION_ID"] then
 96:           @nix_desktop_environment = :gnome
 97:         elsif find_executable("xprop") then
 98:           if %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0 then
 99:             @nix_desktop_environment = :xfce
100:           end
101:         end
102:         Launchy.log "#{self.class.name} : nix_desktop_environment => '#{@nix_desktop_environment}'"
103:       end
104:       return @nix_desktop_environment
105:     end

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

[Source]

     # File lib/launchy/application.rb, line 90
 90:     def nix_desktop_environment
 91:       if not defined? @nix_desktop_environment then
 92:         @nix_desktop_environment = :generic
 93:         if ENV["KDE_FULL_SESSION"] || ENV["KDE_SESSION_UID"] then
 94:           @nix_desktop_environment = :kde
 95:         elsif ENV["GNOME_DESKTOP_SESSION_ID"] then
 96:           @nix_desktop_environment = :gnome
 97:         elsif find_executable("xprop") then
 98:           if %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0 then
 99:             @nix_desktop_environment = :xfce
100:           end
101:         end
102:         Launchy.log "#{self.class.name} : nix_desktop_environment => '#{@nix_desktop_environment}'"
103:       end
104:       return @nix_desktop_environment
105:     end

run the command

[Source]

     # File lib/launchy/application.rb, line 153
153:     def run(cmd,*args)
154:       Launchy.log "#{self.class.name} : Spawning on #{my_os_family} : #{cmd} #{args.inspect}"
155: 
156:       if my_os_family == :windows then
157:         # NOTE: the command is purposely omitted here because
158:         #       When "cmd /c start filename" is
159:         #       run, the shell interprets it as two commands:
160:         #       (1) "start" opens a new terminal, and (2)
161:         #       "filename" causes the file to be launched.
162:         system 'cmd', '/c', cmd, *args
163:       else
164:         # fork, and the child process should NOT run any exit handlers
165:         child_pid = fork do
166:           # NOTE: we pass a dummy argument *before*
167:           #       the actual command to prevent sh
168:           #       from silently consuming our actual
169:           #       command and assigning it to $0!
170:           dummy = ''
171:           system 'sh', '-c', '"$@" >/dev/null 2>&1', dummy, cmd, *args
172:           exit!
173:         end
174:         Process.detach(child_pid)
175:       end
176:     end

run the command

[Source]

     # File lib/launchy/application.rb, line 153
153:     def run(cmd,*args)
154:       Launchy.log "#{self.class.name} : Spawning on #{my_os_family} : #{cmd} #{args.inspect}"
155: 
156:       if my_os_family == :windows then
157:         # NOTE: the command is purposely omitted here because
158:         #       When "cmd /c start filename" is
159:         #       run, the shell interprets it as two commands:
160:         #       (1) "start" opens a new terminal, and (2)
161:         #       "filename" causes the file to be launched.
162:         system 'cmd', '/c', cmd, *args
163:       else
164:         # fork, and the child process should NOT run any exit handlers
165:         child_pid = fork do
166:           # NOTE: we pass a dummy argument *before*
167:           #       the actual command to prevent sh
168:           #       from silently consuming our actual
169:           #       command and assigning it to $0!
170:           dummy = ''
171:           system 'sh', '-c', '"$@" >/dev/null 2>&1', dummy, cmd, *args
172:           exit!
173:         end
174:         Process.detach(child_pid)
175:       end
176:     end

used only for running tests

[Source]

     # File lib/launchy/application.rb, line 148
148:     def testing_app_list
149:       []
150:     end

used only for running tests

[Source]

     # File lib/launchy/application.rb, line 148
148:     def testing_app_list
149:       []
150:     end

On windows a good general default is the ‘start’ Command Shell command

[Source]

     # File lib/launchy/application.rb, line 136
136:     def windows_app_list
137:       Launchy.log "#{self.class.name} : Using 'start' command on windows."
138:       %w[ start ]
139:     end

On windows a good general default is the ‘start’ Command Shell command

[Source]

     # File lib/launchy/application.rb, line 136
136:     def windows_app_list
137:       Launchy.log "#{self.class.name} : Using 'start' command on windows."
138:       %w[ start ]
139:     end

[Validate]