I want to see which files got sourced while starting the Z-shell. Does it even keep track and if yes is there a way to list all the files?
Show all sourced files in ZSH
You could do a
setopt SOURCE_TRACE
at the beginning of the very first file which gets sourced. See man zshoptions
.
I presume the first file sourced is .zshrc, right? Actually it doesn't matter, since all the files I'm interested in are loaded from .zshrc. Thanks for the help –
Apiarian
No. Actually, which files are sourced depend on how the shell is run (login shell? interactive shell?). You have to look up the man pages to find the exact sequence of files being sourced in your particular case. –
Patrimony
@Apiarian The order in which
zsh
loads its configuration files can be found in its manual. Keep in mind that code added to /etc/zshenv
or $ZDOTDIR/.zshenv
will be run even for zsh scripts. If you are only interested in interactive sessions, ~/.zshrc
is indeed the correct place. –
Weaver If the goal is to see all files that get sourced,
/etc/zshenv
would indeed be the correct place to enable it (at least, temporarily; you wouldn't want to leave it enabled). –
Housebreaker Instead of editing files, you can also do
/bin/zsh -o SOURCE_TRACE
–
Goldwin To understand exactly how zsh configuration files are read and in what order, you must read the "STARTUP/SHUTDOWN FILES" section of man zsh
.
Here are the most relevant excerpts:
Commands are first read from /etc/zshenv [...].
Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile. Then,if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
[...]
If ZDOTDIR is unset, HOME is used instead. Files listed above as being in /etc may be in another directory, depending on the installation.
As that last note suggest, on some distributions, the system-wide configuration files listed above may be in /etc/zsh/
instead of directly in /etc/
.
© 2022 - 2024 — McMap. All rights reserved.