[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-readline] [PATCH] Comply with the XDG base directory specification
From: |
Astril Hayato |
Subject: |
[Bug-readline] [PATCH] Comply with the XDG base directory specification |
Date: |
Thu, 20 Mar 2014 22:15:36 +0000 |
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 <address@hidden>
---
bind.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/bind.c b/bind.c
index 8acf4ac..8db4d47 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,31 @@ 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)
+ 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.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-readline] [PATCH] Comply with the XDG base directory specification,
Astril Hayato <=