lib/launchy/spawnable/application.rb in launchy-0.2.0 vs lib/launchy/spawnable/application.rb in launchy-0.2.1

- old
+ new

@@ -25,29 +25,11 @@ false end end 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 - # http://portland.freedesktop.org/wiki/XdgUtils - 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 - - # find an executable in the available paths + # find an executable in the available paths # mkrf did such a good job on this I had to borrow it. def find_executable(bin,*paths) paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty? paths.each do |path| file = File.join(path,bin) @@ -88,10 +70,31 @@ $stderr.puts "Unknown OS familiy for '#{test_os}'. Please report this bug to #{Launchy::SPEC.email}" family = :unknown end end 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 + # http://portland.freedesktop.org/wiki/XdgUtils + 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 "nix_desktop_environment => #{@nix_dekstop_environment}" + end + return @nix_desktop_environment + end # find an executable in the available paths def find_executable(bin,*paths) Application.find_executable(bin,*paths) end @@ -102,9 +105,28 @@ end # detect what the current os is and return :windows, :darwin or :nix def my_os_family(test_os = my_os) Application.my_os_family(test_os) + 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. + def app_list + @app_list ||= self.send("#{my_os_family}_app_list") + end + + # On darwin a good general default is the 'open' executable. + def darwin_app_list + Launchy.log "Using 'open' application on darwin." + [ find_executable('open') ] + end + + # On windows a good general default is the 'start' Command Shell command + def windows_app_list + Launchy.log "Using 'start' command on windows." + %w[ start ] end # run the command def run(cmd,*args) args.unshift(cmd)