zsh-workers
 help / color / mirror / code / Atom feed
From: "Jörg Sommer" <joerg@jo-so.de>
To: zsh-workers@zsh.org
Cc: "Jörg Sommer" <joerg@jo-so.de>
Subject: [PATCH] init.sourcehome: look in ~/.config/zsh for files
Date: Mon,  1 Jan 2024 20:59:24 +0100	[thread overview]
Message-ID: <f14bdf8880777c171515fc147a4084de955fd6b8.1704139164.git.joerg@jo-so.de> (raw)

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



             reply	other threads:[~2024-01-01 20:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-01 19:59 Jörg Sommer [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f14bdf8880777c171515fc147a4084de955fd6b8.1704139164.git.joerg@jo-so.de \
    --to=joerg@jo-so.de \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).