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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2024-01-01 20:06 UTC (permalink / raw)
  To: Jörg Sommer; +Cc: zsh-workers

On Mon, Jan 1, 2024 at 12:00 PM Jörg Sommer <joerg@jo-so.de> wrote:
>
> The [XDG Base Directory Specification][1] mandates

I think we long ago decided that we're not going to attempt to comply with XDG.


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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-01 20:06 ` Bart Schaefer
@ 2024-01-01 21:14   ` Jörg Sommer
  2024-01-01 22:25     ` earnestly
  2024-01-01 23:31     ` Bart Schaefer
  0 siblings, 2 replies; 12+ messages in thread
From: Jörg Sommer @ 2024-01-01 21:14 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

Bart Schaefer schrieb am Mo 01. Jan, 12:06 (-0800):
> On Mon, Jan 1, 2024 at 12:00 PM Jörg Sommer <joerg@jo-so.de> wrote:
> >
> > The [XDG Base Directory Specification][1] mandates
> 
> I think we long ago decided that we're not going to attempt to comply with XDG.

I think this is reasonable, because XDG is very complex and Zsh should run
on many different systems. But wouldn't it be possible to support a minimal
subset, e.g. like ~/.config, to allow using some XDG features? Many other
features like XDG_DATA_DIR can be solved in zshrc.


Regards Jörg

-- 
Dadurch, dass man einen anderen ins Irrenhaus sperrt,
beweist man noch nicht seinen eigenen Verstand.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  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:31     ` Bart Schaefer
  1 sibling, 1 reply; 12+ messages in thread
From: earnestly @ 2024-01-01 22:25 UTC (permalink / raw)
  To: zsh-workers

On Mon, Jan 01, 2024 at 10:14:53PM +0100, Jörg Sommer wrote:
> But wouldn't it be possible to support a minimal
> subset, e.g. like ~/.config, to allow using some XDG features?

Please don't make up your own standards like this, I don't use ~/.config
for example.

You can already use ZDOTDIR to achieve most of what you want; the only
discussion was regarding the use of a preceeding . (dot) for the files
when not directly under HOME.


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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-01 22:25     ` earnestly
@ 2024-01-01 22:41       ` Wesley Schwengle
  2024-01-01 23:42         ` earnestly
  0 siblings, 1 reply; 12+ messages in thread
From: Wesley Schwengle @ 2024-01-01 22:41 UTC (permalink / raw)
  To: zsh-workers

On 1/1/24 18:25, earnestly wrote:
> On Mon, Jan 01, 2024 at 10:14:53PM +0100, Jörg Sommer wrote:
>> But wouldn't it be possible to support a minimal
>> subset, e.g. like ~/.config, to allow using some XDG features?
> 
> Please don't make up your own standards like this, I don't use ~/.config
> for example.

That's not an "own standard". Many applications use ~/.config, eg git, 
google-chrome, i3, signal, vlc, transmission, kitty, yarn, asciinema, 
and many more.

It is defined in the XDG standard that the submitter added:

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

 > $XDG_CONFIG_HOME defines the base directory relative to which user-
 > specific configuration files should be stored. If $XDG_CONFIG_HOME is
 > either not set or empty, a default equal to $HOME/.config should be
 > used.

Cheers,
Wesley

-- 
Wesley Schwengle
E: wesley@opndev.io




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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-01 21:14   ` Jörg Sommer
  2024-01-01 22:25     ` earnestly
@ 2024-01-01 23:31     ` Bart Schaefer
  2024-01-02  7:01       ` Jörg Sommer
  1 sibling, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2024-01-01 23:31 UTC (permalink / raw)
  To: Jörg Sommer; +Cc: zsh-workers

On Mon, Jan 1, 2024 at 1:15 PM Jörg Sommer <joerg@jo-so.de> wrote:
>
> Bart Schaefer schrieb am Mo 01. Jan, 12:06 (-0800):
> >
> > I think we long ago decided that we're not going to attempt to comply with XDG.
>
> I think this is reasonable, because XDG is very complex and Zsh should run
> on many different systems. But wouldn't it be possible to support a minimal
> subset, e.g. like ~/.config, to allow using some XDG features?

IIRC, the argument goes like this:  Zsh already has 5 config files
(zshenv, zshrc, zprofile, zlogin, zlogout) and three places to look
for each of them (/etc/*, $ZDOTDIR/.*, $HOME/.*) and adding yet
another location makes worse a situation that it's already difficult
to clearly explain and use.  Especially given that it's unclear
whether one location supersedes the other (like ZDOTDIR vs. HOME) or
whether both locations should be sourced (in the manner of /etc and
one of the others).

Some relevant completion files do make reference to the XDG locations.


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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-01 22:41       ` Wesley Schwengle
@ 2024-01-01 23:42         ` earnestly
  2024-01-02  1:13           ` Wesley Schwengle
  0 siblings, 1 reply; 12+ messages in thread
From: earnestly @ 2024-01-01 23:42 UTC (permalink / raw)
  To: zsh-workers

On Mon, Jan 01, 2024 at 10:41:00PM +0000, Wesley Schwengle wrote:
> That's not an "own standard". Many applications use ~/.config, eg git, 
> google-chrome, i3, signal, vlc, transmission, kitty, yarn, asciinema, 
> and many more.

Hardcoding ~/.config is a custom standard, the applications you list all
follow XBDS which derives its value from XDG_CONFIG_HOME with a fallback
on HOME/.config if unset.

The suggest in this thread is to *hardcode* the value of HOME/.config.


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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-01 23:42         ` earnestly
@ 2024-01-02  1:13           ` Wesley Schwengle
  0 siblings, 0 replies; 12+ messages in thread
From: Wesley Schwengle @ 2024-01-02  1:13 UTC (permalink / raw)
  To: zsh-workers

On 1/1/24 19:42, earnestly wrote:
> On Mon, Jan 01, 2024 at 10:41:00PM +0000, Wesley Schwengle wrote:
>> That's not an "own standard". Many applications use ~/.config, eg git,
>> google-chrome, i3, signal, vlc, transmission, kitty, yarn, asciinema,
>> and many more.
> 
> Hardcoding ~/.config is a custom standard, the applications you list all
> follow XBDS which derives its value from XDG_CONFIG_HOME with a fallback
> on HOME/.config if unset.
> 
> The suggest in this thread is to *hardcode* the value of HOME/.config.

That's not how I read the remark, it is stated:

 > But wouldn't it be possible to support a minimal subset, e.g. like
 > ~/.config, to allow using some XDG features?

So, it asks to let zsh behave as if XDG_CONFIG_HOME isn't set, then 
using the default ~/.config

Therefore I don't think this is "a personal or own standard".

Cheers,
Wesley

-- 
Wesley Schwengle
E: wesley@opndev.io




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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-01 23:31     ` Bart Schaefer
@ 2024-01-02  7:01       ` Jörg Sommer
  2024-01-02  7:58         ` Lawrence Velázquez
  0 siblings, 1 reply; 12+ messages in thread
From: Jörg Sommer @ 2024-01-02  7:01 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 999 bytes --]

Bart Schaefer schrieb am Mo 01. Jan, 15:31 (-0800):
> On Mon, Jan 1, 2024 at 1:15 PM Jörg Sommer <joerg@jo-so.de> wrote:
> >
> > Bart Schaefer schrieb am Mo 01. Jan, 12:06 (-0800):
> > >
> > > I think we long ago decided that we're not going to attempt to comply with XDG.
> >
> > I think this is reasonable, because XDG is very complex and Zsh should run
> > on many different systems. But wouldn't it be possible to support a minimal
> > subset, e.g. like ~/.config, to allow using some XDG features?
> 
> IIRC, the argument goes like this:  Zsh already has 5 config files
> (zshenv, zshrc, zprofile, zlogin, zlogout) and three places to look
> for each of them (/etc/*, $ZDOTDIR/.*, $HOME/.*) and adding yet

Would it be an option to initialize ZDOTDIR with ~/.config/zsh, if it
exists? This would not require the setting of ZDOTDIR in /etc, i.e. asking
the administrator to make the change.

-- 
“Science is the game we play with God to find out what his rules are.”

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 269 bytes --]

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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  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
  0 siblings, 2 replies; 12+ messages in thread
From: Lawrence Velázquez @ 2024-01-02  7:58 UTC (permalink / raw)
  To: Jörg Sommer, Bart Schaefer; +Cc: zsh-workers

On Tue, Jan 2, 2024, at 2:01 AM, Jörg Sommer wrote:
> Would it be an option to initialize ZDOTDIR with ~/.config/zsh, if it
> exists?

This would still make the already-complicated startup process even
more complicated.

> This would not require the setting of ZDOTDIR in /etc, i.e. asking
> the administrator to make the change.

Changing /etc/zshenv is not necessary.  One can easily

    - put all the startup files in $HOME/.config/zsh
    - set ZDOTDIR=$HOME/.config/zsh in $HOME/.config/zsh/.zshenv
    - symlink $HOME/.config/zsh/.zshenv to $HOME/.zshenv

(Or something similar.)

-- 
vq


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

* RE: Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-02  7:58         ` Lawrence Velázquez
@ 2024-01-02 11:18           ` zeurkous
  2024-01-02 20:00           ` Bart Schaefer
  1 sibling, 0 replies; 12+ messages in thread
From: zeurkous @ 2024-01-02 11:18 UTC (permalink / raw)
  To: Lawrence Velázquez, Jörg Sommer, Bart Schaefer; +Cc: zsh-workers

Haai,

On Tue, 02 Jan 2024 02:58:40 -0500, =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= <larryv@zsh.org> wrote:
>     - symlink $HOME/.config/zsh/.zshenv to $HOME/.zshenv

This might well be the step that XDG adherents object to.

To me, it appears that XDG is just one of the many attempts to redefine
what "UNIX" means. Since me's also somewhat invested in this kind of
thinking (``bring more consistency to UNIX''), mesympathizes -- but me's
also painfully aware that such modifications result in UNIX not being
UNIX anymore (which is not necessarily a bad thing by itself).

Thus, and since XDG adherence is not part of our goals here anyhow, me
suggestion for OP is to maintain a separate port of zsh to his cherised
XDG environment.

        --zeurkous.

-- 
Friggin' Machines!


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

* Re: [PATCH] init.sourcehome: look in ~/.config/zsh for files
  2024-01-02  7:58         ` Lawrence Velázquez
  2024-01-02 11:18           ` zeurkous
@ 2024-01-02 20:00           ` Bart Schaefer
  1 sibling, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2024-01-02 20:00 UTC (permalink / raw)
  To: zsh-workers

On Mon, Jan 1, 2024 at 11:59 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Tue, Jan 2, 2024, at 2:01 AM, Jörg Sommer wrote:
> > Would it be an option to initialize ZDOTDIR with ~/.config/zsh, if it
> > exists?
>
> This would still make the already-complicated startup process even
> more complicated.

It also doesn't address the question of whether the file names inside
~/.config/zsh/ also start with a dot.  Although I don't think the XDG
spec says so, I have the impression that the expectation is that files
in the config directory are not hidden.

> > This would not require the setting of ZDOTDIR in /etc, i.e. asking
> > the administrator to make the change.
>
> Changing /etc/zshenv is not necessary.

I would not object to a change to zsh-newuser-install to set up the
linkages and ZDOTDIR when $XDG_CONFIG_HOME is detected.  This could be
accomplished (and solve the are-the-files-hidden question) by placing
"source" commands in the usual startup locations.  OTOH we already
went through one contentious and eventually abandoned attempt to
update zsh-newuser-install, so this may be a nonstarter.

Alternately, an XDG section could be added to StartupFiles/zshenv, so
that dropping that file in as ~/.zshenv would accomplish the desired
effect.


^ 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).