zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] init.sourcehome: look in ~/.config/zsh for files
@ 2024-01-01 19:59 Jörg Sommer
  2024-01-01 20:06 ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Jörg Sommer @ 2024-01-01 19:59 UTC (permalink / raw)
  To: zsh-workers; +Cc: Jörg Sommer

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



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-01-02 20:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-01 19:59 [PATCH] init.sourcehome: look in ~/.config/zsh for files Jörg Sommer
2024-01-01 20:06 ` Bart Schaefer
2024-01-01 21:14   ` Jörg Sommer
2024-01-01 22:25     ` earnestly
2024-01-01 22:41       ` Wesley Schwengle
2024-01-01 23:42         ` earnestly
2024-01-02  1:13           ` Wesley Schwengle
2024-01-01 23:31     ` Bart Schaefer
2024-01-02  7:01       ` Jörg Sommer
2024-01-02  7:58         ` Lawrence Velázquez
2024-01-02 11:18           ` zeurkous
2024-01-02 20:00           ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).