linux - (天哪-)zsh 行为 : `$ command_name` at home directory results in `cd command_name` effect

标签 linux shell path zsh oh-my-zsh

我目前正在将 zshoh-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/

相关文章:

linux - 我的 $PATH 和 bash 命令遇到问题

windows - 跨 Windows 操作系统的命令行提示路径

linux - compiler.h 文件中有 __cond_lock(x,c) 定义,但没有 __cond_unlock(x,c) 定义?

c++ - 用c++编写插件系统

linux - 如何为 Linux、OS X、Windows 制作 Travis CI 测试包?

linux - 为什么 Linux 上的 read(2) 调用比磁盘 IO 上的调用多花费几毫秒?

linux - 在管道之后无法在源脚本中更改 bash 变量?

linux - 使用shell脚本删除前10个最大的常规文件

php - 如果命令在 mac 终端内运行,如何让 shell_exec 表现得像命令一样?

actionscript-3 - 评估 AS3 中包含嵌套影片剪辑的路径字符串