不在自动完成中建议当前目录

不在自动完成中建议当前目录

我是 ZSH 的长期用户。在我看来,我很久以前就有这个功能,但后来我重写了我的 .zshrc (很久以前),现在我时不时地想念这个功能。 (当然,时间太久了,记忆可能有问题。)

我想要的是,当我自动完成(例如按选项卡等)时,如果我从 1 级(即“..”)或更高级别开始,我不需要来自当前目录的建议。

所以如果我这样做

/usr/share$ cd ../<tab>

然后我想要我当前的目录作为建议

/usr/share$ cd ../share/

问题是针对 ZSH 的,但我很想知道是否也可以在 Bash 中完成。

答案1

http://zshwiki.org/home/examples/compsys/ignore#ignore_parent_directory

zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd

另请参阅info zsh ignore-parents详细信息。以下为 zsh 5.4.2 转载:

忽略父母

 The style is tested without a tag by the function completing
 pathnames in order to determine whether to ignore the names of
 directories already mentioned in the current word, or the name of
 the current working directory.  The value must include one or both
 of the following strings:

 parent
      The name of any directory whose path is already contained in
      the word on the line is ignored.  For example, when completing
      after foo/../, the directory foo will not be considered a
      valid completion.

 pwd
      The name of the current working directory will not be
      completed; hence, for example, completion after ../ will not
      use the name of the current directory.

 In addition, the value may include one or both of:

 ..
      Ignore the specified directories only when the word on the
      line contains the substring '../'.

 directory
      Ignore the specified directories only when names of
      directories are completed, not when completing names of files.

 Excluded values act in a similar fashion to values of the
 ignored-patterns style, so they can be restored to consideration by
 the _ignored completer.

相关内容