展示ZSH中所有被引用的文件

6

我想查看启动Z-shell时被调用的文件。它是否会跟踪并且如果可以,请问有没有一种方法列出所有这些文件?

2个回答

7
你可以执行一个

setopt SOURCE_TRACE

在第一个被引用的文件的开头。请参阅man zshoptions


我猜测第一个被调用的文件是.zshrc,对吗?实际上这并不重要,因为我感兴趣的所有文件都是从.zshrc中加载的。谢谢你的帮助。 - TheEdgeOfRage
不,实际上源文件取决于 shell 运行的方式(登录 shell?交互式 shell?)。您必须查阅 man 手册来查找在您的特定情况下被源化的确切文件序列。 - user1934428
2
@TheEdgeOfRage zsh 加载其配置文件的顺序可以在其手册中找到。请注意,添加到 /etc/zshenv$ZDOTDIR/.zshenv 中的代码将运行即使是 zsh 脚本。如果您只对交互式会话感兴趣,则 ~/.zshrc 确实是正确的地方。 - Adaephon
2
如果目标是查看所有被源引用的文件,则/etc/zshenv确实是启用它的正确位置(至少是暂时的;您不希望将其启用)。 - chepner
2
除了编辑文件,你也可以执行/bin/zsh -o SOURCE_TRACE - casr

0
要了解zsh配置文件的读取方式和顺序,您必须阅读man zsh中的"STARTUP/SHUTDOWN FILES"部分。
以下是最相关的摘录:
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.

正如最后的注释所示,在某些发行版中,上面列出的系统范围配置文件可能在/etc/zsh/而不是直接在/etc/中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接