summaryrefslogtreecommitdiff
path: root/lib/reline
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-04-21 18:17:27 +0900
committeraycabta <aycabta@gmail.com>2020-04-24 16:45:07 +0900
commit81b0b7919718bf7f8a6bd9590651b62279977327 (patch)
treee1316670e2db7b804983ef5368a0335cce574025 /lib/reline
parent71f84018b7fada5c32dfc384f856b6099cc0da6e (diff)
[ruby/reline] Support XDG_CONFIG_HOME
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. https://github.com/ruby/reline/commit/97f1e7db04
Diffstat (limited to 'lib/reline')
-rw-r--r--lib/reline/config.rb22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 53b868fd2e..0e5488eefb 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -3,8 +3,6 @@ require 'pathname'
class Reline::Config
attr_reader :test_mode
- DEFAULT_PATH = '~/.inputrc'
-
KEYSEQ_PATTERN = /\\(?:C|Control)-[A-Za-z_]|\\(?:M|Meta)-[0-9A-Za-z_]|\\(?:C|Control)-(?:M|Meta)-[A-Za-z_]|\\(?:M|Meta)-(?:C|Control)-[A-Za-z_]|\\e|\\[\\\"\'abdfnrtv]|\\\d{1,3}|\\x\h{1,2}|./
class InvalidInputrc < RuntimeError
@@ -86,14 +84,28 @@ class Reline::Config
def inputrc_path
case ENV['INPUTRC']
when nil, ''
- DEFAULT_PATH
else
- ENV['INPUTRC']
+ return File.expand_path(ENV['INPUTRC'])
+ end
+
+ # 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)
+
+ case ENV['XDG_CONFIG_HOME']
+ when nil, ''
+ path = File.expand_path('~/.config/readline/inputrc')
+ return path if File.exist?(path)
+ else
+ path = File.expand_path("#{ENV['XDG_CONFIG_HOME']}/readline/inputrc")
+ return path if File.exist?(path)
end
end
def read(file = nil)
- file ||= File.expand_path(inputrc_path)
+ file ||= inputrc_path
begin
if file.respond_to?(:readlines)
lines = file.readlines