我如何使用zsh'command'选项来执行内置的'source'命令?
每次我的 shell 获取文件时,我都试图记录。我正在使用 zsh,所以我进入了 zshenv 并添加了这个功能。
source() {
echo "sourcing $1"
command source $1
}
这个想法是每次“源 [文件]”出现在我的一个点文件中并被执行时,它应该先将操作打印到终端,然后再实际获取文件。
相反,我收到了一些这样的错误
sourcing /Users/js/.cargo/env
source:2: command not found: source
sourcing /Users/js/.sources/postgres-env.sh
source:2: command not found: source
sourcing /Users/js/.oh-my-zsh/oh-my-zsh.sh
source:2: command not found: source
sourcing /Users/js/.iterm2_shell_integration.zsh
source:2: command not found: source
在这里使用带有 zsh 的 shell 'command' 选项来调用 source 的正确方法是什么?
回答
command旨在专门调用外部命令。例如,如果你有一个别名或函数git,command git将绕过那些。
您正在寻找builtin将命令查找限制为仅内置命令的命令。
source() {
echo "sourcing $1"
builtin source "$1"
}