[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>
This commit is contained in:
parent
5c75dc51b7
commit
725ca2f9d8
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user