Bash
不要在自動完成中建議目前目錄
我是 ZSH 的長期使用者。在我看來,我很久以前就有這個功能,但後來我重寫了我的 .zshrc(很久以前),現在我時不時地想念這個功能。(當然,因為是很久以前,我的記憶可能有問題。)
我想要的是,當我自動完成(例如按 Tab 等)時,如果我從 1 級以上(即’..’)或更高級別開始,我不希望來自目前目錄的建議。
所以如果我這樣做
/usr/share$ cd ../<tab>
那麼我不希望我的目前目錄作為建議
/usr/share$ cd ../share/
問題是針對 ZSH,但我很想知道它是否也可以在 Bash 中完成。
來自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.