(oh-my-)zsh 行为:`$ command_name` at home directory results in `cd command_name` effect

(oh-my-)zsh behaviour: `$ command_name` at home directory results in `cd command_name` effect

我目前正在将 zshoh-my-zsh 一起使用,并且我 运行 陷入了令人讨厌的 shell 行为。

我一定是在编辑我的 .zshrc 时在 $PATH 导出中做了一个微妙但重大的更改,因为发生了以下事情:

~/ 中的 shell 提示符处发出,例如 flutter 命令...

$ flutter

...结果:

$ ~/flutter/ (好像调用 $ flutter 被解释为 $ cd flutter

但是,在任何其他目录(包括 $ ~/flutter 中发出 $ flutter 会导致 正确执行 flutter 命令。 go 和其他人也一样。

我的 .zshrc 上的行 2 按以下方式导出 $PATH

export PATH=$HOME/bin:$HOME/.emacs.d:$HOME/flutter/bin/cache/dart-sdk:$HOME/flutter/bin/cache/dart-sdk/bin:$HOME/.pub-cache/bin:$HOME/.composer/vendor/bin:$HOME/.cargo/env:$HOME/.platformio/penv/bin:$HOME/flutter/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/lib/theme-and-appearance.zsh.

中的 oh-my-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