我目前正在将 zsh
与 oh-my-zsh
一起使用,并且遇到了烦人的 shell 行为。
在编辑 .zshrc
时,我一定在 $PATH
导出中进行了微妙但重大的更改,因为发生了以下情况:
在 ~/
中的 shell 提示符下,发出例如 flutter
命令...
$颤振
...结果:
$ ~/flutter/
(就好像调用 $ flutter
已被解释为 $ cd flutter
)
但是,在任何其他目录(包括 $ ~/flutter
)中发出 $ flutter
都会导致 flutter
命令正确执行。对于 go
和其他人来说也是如此。
我的 .zshrc
上的 2
行以以下方式导出 $PATH
:
导出路径= $ home/bin:$ home/.emacs.d:$ home/flutter/flutter/bin/cache/dart-sdk:$ home/flutter/flutter/bin/cache/dart-sdk/bin:$ home/.pub-cache/.pub-cache/bin:$ home/.composer/.composer/.composer/.composer/.composer/vender/vill/enbuth/enbuth/.car/.car/.car gutter/$ kinlgo: bin:$ path
我一直在将 .zshrc
版本与其他备份进行比较,我可能遗漏了一些内容,但没有发现任何差异。
您认为哪里不对劲?
如果您以前遇到过这种烦恼,您是如何解决的?
最佳答案
说明
这是一个名为 AUTO_CD
的功能。
AUTO_CD (-J)
If a command is issued that can’t be executed as a normal command, and the command is the name of a directory, perform the cd command to that directory.
http://zsh.sourceforge.net/Doc/Release/Options.html#Changing-Directories
AUTO_CD
由 oh-my-zsh 在文件 oh-my-zsh/lib/theme-and-appearance.zsh
中启用.
...
setopt auto_cd
setopt multios
setopt prompt_subst
[[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO=""
...
解决方案
加载oh-my-zsh
后在~/.zshrc
中添加以下命令以禁用此功能。
unsetopt AUTO_CD
关于linux - (天哪-)zsh 行为 : `$ command_name` at home directory results in `cd command_name` effect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58359826/