[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
|
module ExtendCommand
|
||||||
class Edit < Nop
|
class Edit < Nop
|
||||||
category "Misc"
|
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
|
class << self
|
||||||
def transform_args(args)
|
def transform_args(args)
|
||||||
@ -45,12 +45,12 @@ module IRB
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if editor = ENV['EDITOR']
|
if editor = (ENV['VISUAL'] || ENV['EDITOR'])
|
||||||
puts "command: '#{editor}'"
|
puts "command: '#{editor}'"
|
||||||
puts " path: #{path}"
|
puts " path: #{path}"
|
||||||
system(*Shellwords.split(editor), path)
|
system(*Shellwords.split(editor), path)
|
||||||
else
|
else
|
||||||
puts "Can not find editor setting: ENV['EDITOR']"
|
puts "Can not find editor setting: ENV['VISUAL'] or ENV['EDITOR']"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -920,12 +920,15 @@ module TestIRB
|
|||||||
|
|
||||||
class EditTest < CommandTestCase
|
class EditTest < CommandTestCase
|
||||||
def setup
|
def setup
|
||||||
|
@original_visual = ENV["VISUAL"]
|
||||||
@original_editor = ENV["EDITOR"]
|
@original_editor = ENV["EDITOR"]
|
||||||
# noop the command so nothing gets executed
|
# noop the command so nothing gets executed
|
||||||
ENV["EDITOR"] = ": code"
|
ENV["VISUAL"] = ": code"
|
||||||
|
ENV["EDITOR"] = ": code2"
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
ENV["VISUAL"] = @original_visual
|
||||||
ENV["EDITOR"] = @original_editor
|
ENV["EDITOR"] = @original_editor
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -988,5 +991,18 @@ module TestIRB
|
|||||||
assert_match(/path: .*\/lib\/irb\.rb/, out)
|
assert_match(/path: .*\/lib\/irb\.rb/, out)
|
||||||
assert_match("command: ': code'", out)
|
assert_match("command: ': code'", out)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user