
私は zsh の補完とそのメニューの動作を変更しようとしています。行き詰まっており、大量のドキュメントを読んだため頭が混乱しています。
以下は単なる例です。 に特化しない回答をお願いしますcd
。
補完が明確な場合にのみ選択メニューを表示するように zsh を設定しました ( zstyle ':completion:*:*:*:*:*' menu select=2
)。
エイリアス がありますalias cd='nocorrect cd'
。 (スペースなし) と入力するとcd<TAB>
、zsh はそれが明確であるとみなし、エイリアスを補完します。zsh はそれが明確であるとみなします。実際、 と入力するとcd<^D>
、1 つの可能な補完のみが表示されます。私の考えでは、 などの他の補完オプションも表示されるはずですcdiff
。実際、 と入力するとcd<^Xn>
、それらの他のオプションが表示されます。これは、ZSH ユーザーズガイド、セクション 6.5.2。
何が起こっているのかはなんとなく分かります。私はコンプリーターを に設定しているのでzstyle ':completion:*' completer _expand _expand_alias _complete _ignored _match _correct _approximate _prefix
、そのエイリアスの拡張が最優先事項であると考える理由は理解できます。ただ、なぜそれがのみオプション。
tag-order
ユーザーガイドの2番目の例のように、それは と関係があると思います。セクション6.4.2:completion::complete:-command-::
ただし、このコンテキスト ( ) や、それが継承する可能性のある他のものには、そのような設定はありません。
私の完了関連の設定はすべてこのファイルはGithubにあります:completion:
そこから上に進むと、私の zsh 設定全体を見ることができます。ただし、このファイルの外部には、 を含めて何も設定していないので.zshrc
、何かがそれを上書きしているとは思えません。
それで、私が望む動作を得るために何をすべきか誰か説明してくれませんか?
参考までに、私は Prezto フレームワークで zsh を使用していますが、問題は組み込みの 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).