Permalink
Browse files

Allow the VISUAL environment variable for GUI editors

  • Loading branch information...
1 parent 7147a13 commit c16c4e5756faab5b97cc63d784ceeecbbfcfa068 @tomlea tomlea committed with indirect Mar 25, 2010
Showing with 15 additions and 6 deletions.
  1. +8 −4 lib/bundler/cli.rb
  2. +7 −2 spec/other/open_spec.rb
View
12 lib/bundler/cli.rb
@@ -162,10 +162,14 @@ def exec(*)
desc "open GEM", "Opens the source directory of the given bundled gem"
def open(name)
- editor = ENV['EDITOR']
- return Bundler.ui.info("To open a bundled gem, set $EDITOR") if editor.nil? || editor.empty?
- command = "#{editor} #{locate_gem(name)}"
- Bundler.ui.info "Could not run '#{command}'" unless system(command)
+ editor = [ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
+ if editor
+ command = "#{editor} #{locate_gem(name)}"
+ success = system(command)
+ Bundler.ui.info "Could not run '#{command}'" unless success
+ else
+ Bundler.ui.info("To open a bundled gem, set $EDITOR")
+ end
end
desc "version", "Prints the bundler's version information"
View
9 spec/other/open_spec.rb
@@ -8,13 +8,18 @@
G
end
+ it "opens the gem with VISUAL if set" do
+ bundle "open rails", :env => {"EDITOR" => "echo editor", "VISUAL" => "echo visual"}
+ out.should == "visual #{default_bundle_path('gems', 'rails-2.3.2')}"
+ end
+
it "opens the gem with EDITOR if set" do
- bundle "open rails", :env => {"EDITOR" => "echo editor"}
+ bundle "open rails", :env => {"EDITOR" => "echo editor", "VISUAL" => ''}
out.should == "editor #{default_bundle_path('gems', 'rails-2.3.2')}"
end
it "complains if gem not in bundle" do
- bundle "open missing", :env => {"EDITOR" => "echo editor"}
+ bundle "open missing", :env => {"EDITOR" => "echo editor", "VISUAL" => ''}
out.should match(/could not find gem 'missing'/i)
end
end

0 comments on commit c16c4e5

Please sign in to comment.