Class: Launchy::Spawnable::Application
- Inherits:
-
Object
- Object
- Launchy::Spawnable::Application
- Defined in:
- lib/launchy/spawnable/application.rb
Direct Known Subclasses
Constant Summary collapse
- KNOWN_OS_FAMILIES =
[ :windows, :darwin, :nix ]
Class Method Summary collapse
- .application_classes ⇒ Object
- .find_application_class_for(*args) ⇒ Object
-
.find_executable(bin, *paths) ⇒ Object
find an executable in the available paths 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.
-
.nix_desktop_environment ⇒ Object
Determine the appropriate desktop environment for *nix machine.
Instance Method Summary collapse
-
#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 or :nix.
-
#run(cmd, *args) ⇒ Object
run the command.
Class Method Details
.application_classes ⇒ Object
14 15 16 |
# File 'lib/launchy/spawnable/application.rb', line 14 def application_classes @application_classes ||= [] end |
.find_application_class_for(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/launchy/spawnable/application.rb', line 18 def find_application_class_for(*args) Launchy.log "finding application classes for [#{args.join(' ')}]" application_classes.find do |klass| if klass.handle?(*args) then Launchy.log " #{klass.name}" true else false end end end |
.find_executable(bin, *paths) ⇒ Object
find an executable in the available paths mkrf did such a good job on this I had to borrow it.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/launchy/spawnable/application.rb', line 50 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 "found executable #{file}" return file end end Launchy.log "Unable to find `#{bin}' in paths #{paths.join(', ')}" return nil end |
.inherited(sub_class) ⇒ Object
11 12 13 |
# File 'lib/launchy/spawnable/application.rb', line 11 def inherited(sub_class) application_classes << sub_class end |
.my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration
64 65 66 |
# File 'lib/launchy/spawnable/application.rb', line 64 def my_os ::Config::CONFIG['host_os'] end |
.my_os_family(test_os = my_os) ⇒ Object
detect what the current os is and return :windows, :darwin or :nix
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/launchy/spawnable/application.rb', line 69 def my_os_family(test_os = my_os) case test_os 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 /cygwin/i family = :nix else $stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug to #{Launchy::SPEC.email}" family = :unknown end 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/launchy/spawnable/application.rb', line 33 def nix_desktop_environment de = :generic if ENV["KDE_FULL_SESSION"] || ENV["KDE_SESSION_UID"] then de = :kde elsif ENV["GNOME_DESKTOP_SESSION_ID"] then de = :gnome elsif find_executable("xprop") then if %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0 then de = :xfce end end Launchy.log "nix_desktop_environment => #{de}" return de end |
Instance Method Details
#find_executable(bin, *paths) ⇒ Object
find an executable in the available paths
95 96 97 |
# File 'lib/launchy/spawnable/application.rb', line 95 def find_executable(bin,*paths) Application.find_executable(bin,*paths) end |
#my_os ⇒ Object
return the current ‘host_os’ string from ruby’s configuration
100 101 102 |
# File 'lib/launchy/spawnable/application.rb', line 100 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 or :nix
105 106 107 |
# File 'lib/launchy/spawnable/application.rb', line 105 def my_os_family(test_os = my_os) Application.my_os_family(test_os) end |
#run(cmd, *args) ⇒ Object
run the command
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/launchy/spawnable/application.rb', line 110 def run(cmd,*args) args.unshift(cmd) cmd_line = args.join(' ') Launchy.log "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 |