
我正在嘗試修改 zsh 完成及其選單的行為。我被困住了,我讀了太多文檔,這讓我頭暈目眩。
以下僅為範例;我更喜歡不特定於 的答案cd
。
我將 zsh 設定為僅在完成明確時才顯示選擇選單 ( zstyle ':completion:*:*:*:*:*' menu select=2
)。
我有一個別名alias cd='nocorrect cd'
。當我這樣做時cd<TAB>
(沒有空格),zsh 認為它是明確的,並完成別名。 zsh 認為它是明確的——事實上,當我這樣做時cd<^D>
,它只顯示一種可能的完成。在我看來,它應該顯示其他完成選項,例如cdiff
.事實上,當我這樣做時cd<^Xn>
,我會看到其他選擇。這也是在ZSH 使用者指南,第 6.5.2 節。
我好像明白髮生了什麼事。我將完成者設為zstyle ':completion:*' completer _expand _expand_alias _complete _ignored _match _correct _approximate _prefix
,所以我可以理解為什麼它認為擴展該別名是首要任務。我只是不明白為什麼會這樣僅有的選項。
我認為這與 相關tag-order
,就像用戶指南中的第二個範例一樣第6.4.2節。但是,我沒有為此上下文 ( :completion::complete:-command-::
) 設定類似的內容,也沒有它可能繼承的任何其他內容。
我所有與完成相關的設定都在這個文件在Github上。從那裡向上,您可以看到我的 zsh 配置的完整內容;但是,我沒有:completion:
在此文件之外設置任何內容,包括在我的 中.zshrc
,所以我懷疑是否有任何內容覆蓋它。
那麼,有人可以跟我解釋一下該怎麼做才能得到我想要的行為嗎?
僅供參考,我將 zsh 與 Prezto 框架一起使用,我認為這是無關緊要的,因為問題完全與內建 zsh 功能和模組有關。
一些輸出:
cd<TAB>
:只是更改cd
為nocorrect cd
,沒有菜單。
$ cd<^D>
-- alias --
nocorrect cd
$ cd<^Xn>
-- external command --
cdbs-edit-patch cd-fix-profile cdiff
cd-create-profile cd-iccdump
-- builtin command --
cd
-- shell function --
cdls
-- alias --
cd
-- parameter --
CDPATH cdpath
答案1
@Ilua的回答沒有用,但它確實給了我一些關於搜尋內容的想法,並且我解決了問題。
我需要的風格是regular
.從man zshcompsys
:
regular
This style is used by the _expand_alias completer and bindable command.
If set to ‘true’ (the default), regular aliases will be expanded but only in command position.
If it is set to ‘false’, regular aliases will never be expanded.
If it is set to ‘always’, regular aliases will be expanded even if not in command position.
我用過zstyle ':completion:*' regular 'false'
,效果很好。
答案2
我認為您正在尋找accept-exact
想要將其設為 false 的樣式。
男子 zshcompsys
accept-exact
This is tested for the default tag in addition to the tags valid for the current context. If it is set to `true' and any of the trial matches is the same as the string on the command line, this match will immediately
be accepted (even if it would otherwise be considered ambiguous).