From 81b0b7919718bf7f8a6bd9590651b62279977327 Mon Sep 17 00:00:00 2001 From: aycabta Date: Tue, 21 Apr 2020 18:17:27 +0900 Subject: [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 --- lib/reline/config.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'lib/reline') 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 -- cgit v1.2.3