Aki_Peroro

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

前段时间切到了zsh环境,用着确实挺好,方便快捷什么的。
尤其是auto cd这个功能,太方便了,想进入某个目录直接敲目录名就好,完全不用先敲cd再敲目录名。

屏幕快照 2016-02-03 下午11.26.08

就像这样,轻松进入文件夹,多棒!

现在问题就来了!
如果当前目录下有个文件夹的名字和我的某个命令名字相同会出现什么情况?
答案是不确定,时而自动进入文件夹,时而运行命令……
屏幕快照 2016-02-03 下午11.24.57
这一次是进入cmake目录

屏幕快照 2016-02-03 下午11.29.14
这一次又运行了cmake

坑爹呢?!

在终端输入man zshoptions可以查询到zsh所有的option的解释
里面有这么一条

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. This option is only applicable  if the  option SHIN_STDIN  is set, i.e. if commands are being read from standard input. The option  is  designed for interactive use; it is recommended that cd be used explicitly in scripts to avoid ambiguity. 

唔,看起来很像是这货,虽然说是只有在这个命令无法工作的时候才会自动进入文件夹,但是完全没起作用……
这个功能太菜了,我们不要,关掉!

在终端中输入unsetopt AUTO_CD
再试下

屏幕快照 2016-02-03 下午11.50.54
这就对喽!

posted on 2016-02-03 23:56  Aki_Peroro  阅读(600)  评论(0编辑  收藏  举报