You are not logged in.

#1 2022-07-01 10:08:22

Venem
Member
From: Her Majesty's United Kingdom
Registered: 2021-12-17
Posts: 12

[RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

I'm trying to declutter my home directory. The Arch Wiki (https://wiki.archlinux.org/title/XDG_Base_Directory) says that I can remove the ~/.zshenv file by exporting ZDOTDIR in my system zshenv (/etc/zsh/zshenv). I have added

export ZDOTDIR="$HOME"/.config/zsh

to /etc/zsh/zshenv and moved ~/.zshenv to ~/.config/zsh/.zshenv.

It seems that after doing this, zsh now sources the .zshenv file whenever I launch a new shell which was not the case before. I'm not sure whether this is intended behaviour.

My previous setup:
ZDOTDIR is set in ~/.zshenv and ZDOTDIR=~/.config/zsh/
/etc/zsh/zshenv is not used

zsh logs:

zsh -x >.log 2>&1 && exit

output: https://privatebin.net/?836d3c2f7a45a53 … 26kUR3kY1t

Current setup:
(as described above)

zsh -x >.log 2>&1 && exit

output: https://privatebin.net/?4e32f578b4e40a6 … uCuLkmEq6D

Clearly, when setting ZDOTDIR system wide, zsh always sources the user zshenv file.

I'm not a fan of this behaviour because it causes lag. All of my terminals hang for about 1-2 seconds when opened because I export BW_SESSION for my bitwarden-cli setup in .zshenv which takes time to unlock the password store. This isn't a problem when logging in since I don't mind waiting a few seconds but currently, it is really annoying.

How can I move .zshenv from my $HOME without having it always be called?

Thanks in advance

Last edited by Venem (2022-07-01 11:35:04)


btw i use "btw i use"

Offline

#2 2022-07-01 10:42:54

nl6720
The Evil Wiki Admin
Registered: 2016-07-02
Posts: 611

Re: [RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

$ZDOTDIR/.zshenv is supposed to be sourced every time zsh starts unless you unset RCS in /etc/zsh/zshenv. See https://wiki.archlinux.org/title/Zsh#St … down_files and https://man.archlinux.org/man/zsh.1#STA … DOWN_FILES.

Last edited by nl6720 (2022-07-01 10:44:18)

Online

#3 2022-07-01 10:56:49

Venem
Member
From: Her Majesty's United Kingdom
Registered: 2021-12-17
Posts: 12

Re: [RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

So when nothing is set and the default location (~/.zshenv) is used, is it still supposed to be sourced? From my logs it looks like it is only called on login and then never again

Edit: the Wiki entry and manpage both state that it should always be sourced on new instances of zsh. This brings up the question of why it wasn't actually being called before I moved it.

Last edited by Venem (2022-07-01 10:59:52)


btw i use "btw i use"

Offline

#4 2022-07-01 11:00:35

nl6720
The Evil Wiki Admin
Registered: 2016-07-02
Posts: 611

Re: [RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

Yes, it's supposed to be sourced. I have no idea why it didn't get sourced for you before.

Online

#5 2022-07-01 11:15:19

Venem
Member
From: Her Majesty's United Kingdom
Registered: 2021-12-17
Posts: 12

Re: [RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

After doing some testing on a live CD, it seems that setting ZDOTDIR in ~/.zshenv causes zsh to stop sourcing it.

Contents of the test user's ~/.zshenv

export ZDOTDIR="$HOME"/.config/zsh
sleep 5

This waits for 5 seconds whenever su'ing into the user but when opening a new instance of zsh, there is no delay. I tested it without the ZDOTDIR setting and the delay is present every time a new instance of zsh is open.
Seems like a bug (clarification edit: zsh not sourcing the file seems like a bug)

Are there any drawbacks to .zshenv not being sourced? It still looks like all environment variables inside of it are set and accessible from zsh

Last edited by Venem (2022-07-01 11:18:22)


btw i use "btw i use"

Offline

#6 2022-07-01 11:34:36

Venem
Member
From: Her Majesty's United Kingdom
Registered: 2021-12-17
Posts: 12

Re: [RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

Marking topic as resolved.


btw i use "btw i use"

Offline

#7 2022-07-01 12:39:46

ayekat
Member
Registered: 2011-01-17
Posts: 1,597

Re: [RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

Venem wrote:

Seems like a bug (clarification edit: zsh not sourcing the file seems like a bug)

There is no bug. If you export ZDOTDIR=~/.config/zsh in your ~/.zshenv, subsequent invocations of zsh (from the same environment) will attempt to read ~/.config/zsh/.zshenv (which doesn't exist), so the behaviour is exactly as expected.

Re drawbacks to zshenv not being sourced: Depends on what you put in your zshenv. As the manpage states, /etc/zsh/zshenv is sourced in all cases (and this cannot be overridden). What you put in your personal zshenv is then up to you.

Personally, I export ZDOTDIR in $XDG_CONFIG_HOME/zsh/.zshenv, but also symlink the file into my homedir (for the initial invocation, as a sort of "bootstrap"). In both cases, it will read zshenv and (re)export ZDOTDIR there.


pkgshackscfgblag

Offline

#8 2022-07-03 11:57:28

Venem
Member
From: Her Majesty's United Kingdom
Registered: 2021-12-17
Posts: 12

Re: [RESOLVED] .zshenv is always sourced when using ZDOTDIR in...

Thanks for the clarification. It makes more sense now


btw i use "btw i use"

Offline

Board footer

Powered by FluxBB