Skip to content

Commit

Permalink
Allow *nix command lines to have more args
Browse files Browse the repository at this point in the history
Fixes #71
  • Loading branch information
copiousfreetime committed Nov 26, 2013
1 parent 58dd6e2 commit aed917f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/launchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def to_bool( arg )
end

require 'launchy/version'
require 'launchy/argv'
require 'launchy/cli'
require 'launchy/descendant_tracker'
require 'launchy/error'
Expand Down
4 changes: 1 addition & 3 deletions lib/launchy/applications/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def darwin_app_list
def nix_app_list
nix_de = Launchy::Detect::NixDesktopEnvironment.detect
list = nix_de.browsers

list.delete_if { |b| b.nil? || (b.strip.size == 0) }
list.collect { |bin| find_executable( bin ) }.find_all { |x| not x.nil? }
list.find_all { |argv| argv.valid? }
end

# use a call back mechanism to get the right app_list that is decided by the
Expand Down
36 changes: 36 additions & 0 deletions lib/launchy/argv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Launchy
class Argv
attr_reader :argv
def initialize( *args )
@argv = args.flatten
end

def to_s
@argv.join(' ')
end

def to_str
to_s
end

def [](idx)
@argv[idx]
end

def valid?
(not blank?) && executable?
end

def blank?
@argv.empty? || (@argv.first.strip.size == 0)
end

def executable?
::Launchy::Application.find_executable( @argv.first )
end

def ==( other )
@argv == other.argv
end
end
end
12 changes: 6 additions & 6 deletions lib/launchy/detect/nix_desktop_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.detect
end

def self.fallback_browsers
%w[ firefox seamonkey opera mozilla netscape galeon ]
%w[ firefox seamonkey opera mozilla netscape galeon ].map { |x| ::Launchy::Argv.new( x ) }
end

def self.browsers
Expand All @@ -36,7 +36,7 @@ def self.is_current_desktop_environment?
end

def self.browser
'kfmclient'
::Launchy::Argv.new( %w[ kvmclient openURL ] )
end
end

Expand All @@ -46,7 +46,7 @@ def self.is_current_desktop_environment?
end

def self.browser
'gnome-open'
::Launchy::Argv.new( 'gnome-open' )
end
end

Expand All @@ -60,7 +60,7 @@ def self.is_current_desktop_environment?
end

def self.browser
'exo-open'
::Launchy::Argv.new( 'exo-open' )
end
end

Expand All @@ -71,7 +71,7 @@ def self.is_current_desktop_environment?
end

def self.browser
'xdg-open'
::Launchy::Argv.new( 'xdg-open' )
end
end

Expand All @@ -82,7 +82,7 @@ def self.is_current_desktop_environment?
end

def self.browser
[]
::Launchy::Argv.new
end
end

Expand Down
4 changes: 3 additions & 1 deletion spec/detect/nix_desktop_environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
{ "KDE_FULL_SESSION" => Launchy::Detect::NixDesktopEnvironment::Kde,
"GNOME_DESKTOP_SESSION_ID" => Launchy::Detect::NixDesktopEnvironment::Gnome }.each_pair do |k,v|
it "can detect the desktop environment of a *nix machine using ENV[#{k}]" do
ENV.delete( "KDE_FULL_SESSION" )
ENV.delete( "GNOME_DESKTOP_SESSION_ID" )
ENV[k] = "launchy-test"
nix_env = Launchy::Detect::NixDesktopEnvironment.detect
nix_env.must_equal( v )
Expand All @@ -33,6 +35,6 @@
ENV.delete( "GNOME_DESKTOP_SESSION_ID" )
not_found = Launchy::Detect::NixDesktopEnvironment.detect
not_found.must_equal( Launchy::Detect::NixDesktopEnvironment::NotFound )
not_found.browser.must_equal( [] )
not_found.browser.must_equal( Launchy::Argv.new )
end
end

0 comments on commit aed917f

Please sign in to comment.