Skip to content

Commit

Permalink
[ruby/reline] Treat home dir correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Apr 24, 2020
1 parent 81b0b79 commit 9fb2071
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/reline/config.rb
Expand Up @@ -91,8 +91,8 @@ def inputrc_path
# In the XDG Specification, if ~/.config/readline/inputrc exists, then
# ~/.inputrc should not be read, but for compatibility with GNU Readline,
# if ~/.inputrc exists, then it is given priority.
path = File.expand_path('~/.inputrc')
return path if File.exist?(path)
home_rc_path = File.expand_path('~/.inputrc')
return home_rc_path if File.exist?(home_rc_path)

case ENV['XDG_CONFIG_HOME']
when nil, ''
Expand All @@ -102,6 +102,8 @@ def inputrc_path
path = File.expand_path("#{ENV['XDG_CONFIG_HOME']}/readline/inputrc")
return path if File.exist?(path)
end

return home_rc_path
end

def read(file = nil)
Expand Down
3 changes: 1 addition & 2 deletions test/reline/test_config.rb
Expand Up @@ -227,12 +227,11 @@ def test_inputrc
def test_xdg_config_home
home_backup = ENV['HOME']
xdg_config_home_backup = ENV['XDG_CONFIG_HOME']
nonexistence_dir = '/the_nonexistence_dir!!!!!!'
xdg_config_home = File.expand_path("#{@tmpdir}/.config/example_dir")
expected = File.expand_path("#{xdg_config_home}/readline/inputrc")
FileUtils.mkdir_p(File.dirname(expected))
FileUtils.touch(expected)
ENV['HOME'] = nonexistence_dir
ENV['HOME'] = @tmpdir
ENV['XDG_CONFIG_HOME'] = xdg_config_home
assert_equal expected, @config.inputrc_path
FileUtils.rm(expected)
Expand Down

0 comments on commit 9fb2071

Please sign in to comment.