Let the user optionally follow the XDG base directory standard. See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
Signed-off-by: Astril Hayato <astrilhay...@gmail.com> --- Fix a memory leak bug from the previous version bind.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/bind.c b/bind.c index 8acf4ac..f103ac2 100644 --- a/bind.c +++ b/bind.c @@ -870,9 +870,11 @@ rl_re_read_init_file (count, ignore) /* Do key bindings from a file. If FILENAME is NULL it defaults to the first non-null filename from this list: 1. the filename used for the previous call - 2. the value of the shell variable `INPUTRC' - 3. ~/.inputrc - 4. /etc/inputrc + 2. $INPUTRC shell variable + 3. $XDG_CONFIG_HOME/readline/inputrc with $XDG_CONFIG_HOME defaulting to + ~/.config if not set + 4. ~/.inputrc + 5. /etc/inputrc If the file existed and could be opened and read, 0 is returned, otherwise errno is returned. */ int @@ -886,10 +888,34 @@ rl_read_init_file (filename) filename = sh_get_env_value ("INPUTRC"); if (filename == 0 || *filename == 0) { + /* Try to read from the XDG base directory */ + const char *xdg_base_dir = sh_get_env_value ("XDG_CONFIG_HOME"); + if (xdg_base_dir == 0 || *xdg_base_dir == 0) + { + /* Default XDG base directory */ + filename = "~/.config/readline/inputrc"; + if (_rl_read_init_file (filename, 0) == 0) + return 0; + } + else + { + /* $XDG_CONFIG_HOME shell variable is set */ + filename = (char *)xmalloc (strlen (xdg_base_dir) + + strlen ("/readline/inputrc") + 1); + strcpy((char *) filename, xdg_base_dir); + strcat((char *) filename, "/readline/inputrc"); + if (_rl_read_init_file (filename, 0) == 0) + { + xfree((char *) filename); + return 0; + } + xfree((char *) filename); + } + /* On failure try to read from DEFAULT_INPUTRC */ filename = DEFAULT_INPUTRC; - /* Try to read DEFAULT_INPUTRC; fall back to SYS_INPUTRC on failure */ if (_rl_read_init_file (filename, 0) == 0) - return 0; + return 0; + /* Fall back to SYS_INPUTRC as last resort */ filename = SYS_INPUTRC; } -- 1.9.1 _______________________________________________ Bug-readline mailing list Bug-readline@gnu.org https://lists.gnu.org/mailman/listinfo/bug-readline