summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSummer ☀️ <4400771+smmr0@users.noreply.github.com>2023-08-20 11:21:57 -0600
committergit <svn-admin@ruby-lang.org>2023-08-20 17:22:01 +0000
commit725ca2f9d808d180c57eaf49c2dd6bfcb9f701e4 (patch)
tree8ae57c283278d0a0b83170817583a4729c20d6a8
parent5c75dc51b7ea956d94db8123f4501e5e7f5957ae (diff)
[ruby/irb] Support `VISUAL` env var, and prefer it over `EDITOR`
(https://github.com/ruby/irb/pull/686) * Support `VISUAL` env var, and prefer it over `EDITOR` * Update test/irb/test_cmd.rb --------- https://github.com/ruby/irb/commit/399b872c31 Co-authored-by: Stan Lo <stan001212@gmail.com>
-rw-r--r--lib/irb/cmd/edit.rb6
-rw-r--r--test/irb/test_cmd.rb18
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/irb/cmd/edit.rb b/lib/irb/cmd/edit.rb
index 523a1dac5d..69606beea0 100644
--- a/lib/irb/cmd/edit.rb
+++ b/lib/irb/cmd/edit.rb
@@ -8,7 +8,7 @@ module IRB
module ExtendCommand
class Edit < Nop
category "Misc"
- description 'Open a file with the editor command defined with `ENV["EDITOR"]`.'
+ description 'Open a file with the editor command defined with `ENV["VISUAL"]` or `ENV["EDITOR"]`.'
class << self
def transform_args(args)
@@ -45,12 +45,12 @@ module IRB
end
end
- if editor = ENV['EDITOR']
+ if editor = (ENV['VISUAL'] || ENV['EDITOR'])
puts "command: '#{editor}'"
puts " path: #{path}"
system(*Shellwords.split(editor), path)
else
- puts "Can not find editor setting: ENV['EDITOR']"
+ puts "Can not find editor setting: ENV['VISUAL'] or ENV['EDITOR']"
end
end
end
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index dcea020b1e..272f6d3ace 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -920,12 +920,15 @@ module TestIRB
class EditTest < CommandTestCase
def setup
+ @original_visual = ENV["VISUAL"]
@original_editor = ENV["EDITOR"]
# noop the command so nothing gets executed
- ENV["EDITOR"] = ": code"
+ ENV["VISUAL"] = ": code"
+ ENV["EDITOR"] = ": code2"
end
def teardown
+ ENV["VISUAL"] = @original_visual
ENV["EDITOR"] = @original_editor
end
@@ -988,5 +991,18 @@ module TestIRB
assert_match(/path: .*\/lib\/irb\.rb/, out)
assert_match("command: ': code'", out)
end
+
+ def test_edit_with_editor_env_var
+ ENV.delete("VISUAL")
+
+ out, err = execute_lines(
+ "edit",
+ irb_path: __FILE__
+ )
+
+ assert_empty err
+ assert_match("path: #{__FILE__}", out)
+ assert_match("command: ': code2'", out)
+ end
end
end