Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] init.sourcehome: look in ~/.config/zsh for files



The [XDG Base Directory Specification][1] mandates to use the directory
specified in the environment variable *$XDG_CONFIG_HOME* for config files.
And it's rather more complex, because the variable *$XDG_CONFIG_DIRS* should
be used, too. For most of the users a lookup of the config files
in *~/.config/zsh* should be enough.

Therefore, if a file is not found in the home directory, a second try to
find it *without the leading dot* in *~/.config/zsh*.

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.6.html
---
 Src/init.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/Src/init.c b/Src/init.c
index 799ad19f6..628a06e6c 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1679,11 +1679,18 @@ sourcehome(char *s)
     }
 
     {
+	const int h_len = strlen(h);
 	/* Let source() complain if path is too long */
-	VARARR(char, buf, strlen(h) + strlen(s) + 2);
+	VARARR(char, buf, h_len + 13 + (strlen(s) - 1) + 1);
 	sprintf(buf, "%s/%s", h, s);
 	unqueue_signals();
-	source(buf);
+	if (source(buf) == SOURCE_NOT_FOUND && h == home && s[0] == '.'
+	    && ! EMULATION(EMULATE_SH|EMULATE_KSH)) {
+	    queue_signals();
+	    sprintf(&buf[h_len + 1], ".config/zsh/%s", &s[1]);
+	    unqueue_signals();
+	    source(buf);
+	}
     }
 }
 
-- 
2.43.0





Messages sorted by: Reverse Date, Date, Thread, Author