これはDisable auto-completion of remote branches in Git Bash?に関連しています。Zshのリモートブランチの自動補完を無効にしますか?
誰もがzshで同じことをする方法を知っていますか?
これはDisable auto-completion of remote branches in Git Bash?に関連しています。Zshのリモートブランチの自動補完を無効にしますか?
誰もがzshで同じことをする方法を知っていますか?
zstyle :completion::complete:git-checkout:argument-rest:headrefs command "git for-each-ref --format='%(refname)' refs/heads 2>/dev/null"
説明:
がgit checkout <Control-x><h>
がどのようにのzshの補完システムの内部を公開_complete_help
を呼び出しタイピング(<Control-x><h>
を押すのではなく)現在のコンテキストでTabキーを押した場合に動作します。これにより、zshが__git_heads
関数を呼び出してgitブランチヘッドの名前を完成させることが分かります。あなたがwhich __git_heads
を入力する場合は、これらのブランチヘッド名を介して取得していることがわかります。
_call_program headrefs git for-each-ref --format='"%(refname)"' refs/heads refs/remotes 2>/dev/null
幸いにも私たちのために、_call_program
は、ユーザーがデフォルトの動作を変更できるようにするために特別に設計されています。したがって、上記のzstyle
コマンドは、組み込みコマンドの代わりにgit for-each-ref ...
呼び出しを使用するようにzshに指示します。上の呼び出しで、refs/remotes
パラメータを削除したことがわかります。 zstyle
の最初のパラメータは完了コンテキストであり、ユーザがgit checkout
の引数を完了したときに完了システムがheadrefs
タグの完了を要求すると、「」はgit checkout
にのみ適用され、その他のgit
サブ - コマンド。
あなたの.zshrc
ファイルに次の行を追加することでgit checkout
に自動補完を無効にすることができます
compdef -d git checkout
私はリモートブランチの自動補完を避ける方法を探していました。これは、 "エコー"と置き換えることでオートコンプリートエントリの提供を停止します。私はローカル支店の自動完成をしたいと思います。 –
@GalderZamarreño私のzshの知識の範囲を超えていることを恐れる; zshリストを試してみるかもしれません。彼らは役に立つ人のように見えます。 – Christopher
__git_heads
が今だけ支部をチェックすることが表示されますが、完成ファイルではなく__git_refs
を呼び出す。
私はzshの_git
コマンドによって介してプロキシされgit-completion.bash
、このパッチを適用することによって、これをでハッキング:
--- git-completion.bash.old 2015-04-02 16:09:38.000000000 -0700
+++ git-completion.bash 2015-04-02 16:10:24.000000000 -0700
@@ -1032,13 +1032,7 @@
"
;;
*)
- # check if --track, --no-track, or --no-guess was specified
- # if so, disable DWIM mode
- local flags="--track --no-track --no-guess" track=1
- if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
- track=''
- fi
- __gitcomp_nl "$(__git_refs '' $track)"
+ __gitcomp_nl "$(__git_heads)"
;;
esac
}
これは完璧な解決策ではありませんが、私の使用例では機能し、10秒ではなく瞬時に完了します。
あなたがタグの束を参照してくださいgit checkout <Ctrl-X><H>
を入力して、関連するように見えるそのいくつかは以下のとおりです。一見
$ git checkout
tags in context :completion::complete:git-checkout:argument-rest:
remote-branch-names-noprefix (__git_describe_branch __git_describe_commit __git_remote_branch_names_noprefix _git-checkout _git)
heads-remote (__git_describe_branch __git_describe_commit __git_heads_remote __git_heads __git_commits __git_tree_ishs _git-checkout _git)
[...]
、我々は接頭辞なしでリモートブランチ名の提供を停止するremote-branch-names-noprefix
の動作を変更する必要があります。オートコンプリートのエントリが生成されることにつながったコマンドのチェーンがあり、
$ zstyle ':completion:*' group-name ''
$ zstyle ':completion:*' format 'Completing "%d":'
$ git checkout T<Tab>
Completing "remote branch name":
T3522-plugins_and_stuff T7482
Completing "local head":
T7626-async
括弧で上記のタグ名以下:ダブルチェックするために
、のは、使用に関連しているこれらのタグをエントリか見てみましょうそのタグのremote-branch-names-noprefix
のチェーンでは__git_remote_branch_names_noprefix
が適切と思われます。 /usr/share/zsh/functions/Completion/Unix/_git
に見て:
(($+functions[__git_remote_branch_names_noprefix])) ||
__git_remote_branch_names_noprefix() {
declare -a heads
branch_names=(${${${${(f)"$(_call_program remote-branch-refs-noprefix git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}#refs/remotes/}#*/}:#HEAD})
__git_command_successful $pipestatus || return 1
__git_describe_commit branch_names remote-branch-names-noprefix 'remote branch name' "[email protected]"
}
あなたは_call_program
がremote-branch-refs-noprefix
を定義するために使用されるかを見ることができます。この定義をgit-checkout
の場合に変更したいと考えています。
zstyle ':completion::complete:git-checkout:argument-rest:remote-branch-refs-noprefix' command "echo"
どのようにリモートとローカルを2つの別々のセクションに分割するのですか?例えば。私は特別なヘッド( 'HEAD'、' ORIG_HEAD'、 'FETCH_HEAD'など)、ローカルブランチ、そしてリモートブランチを持っていたいと思います。それがどうやって行われるのか分かりません。あなたの答えを拡大するのが簡単ならば、それは膨らみます。そうでなければ、新しい質問を開きます。 –
*これはおそらく*行う方法です。結局のところ、グループ化の仕組みがあります(マニュアルでは 'group-name'と' group-order'を検索します)。しかし、これらのグループにはさまざまな頭があります。別の質問の価値があるでしょう。 –