2012-08-29 7 views

答えて

9
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サブ - コマンド。

+0

どのようにリモートとローカルを2つの別々のセクションに分割するのですか?例えば。私は特別なヘッド( 'HEAD'、' ORIG_HEAD'、 'FETCH_HEAD'など)、ローカルブランチ、そしてリモートブランチを持っていたいと思います。それがどうやって行われるのか分かりません。あなたの答えを拡大するのが簡単ならば、それは膨らみます。そうでなければ、新しい質問を開きます。 –

+0

*これはおそらく*行う方法です。結局のところ、グループ化の仕組みがあります(マニュアルでは 'group-name'と' group-order'を検索します)。しかし、これらのグループにはさまざまな頭があります。別の質問の価値があるでしょう。 –

-1

あなたの.zshrcファイルに次の行を追加することでgit checkoutに自動補完を無効にすることができます

compdef -d git checkout 
+1

私はリモートブランチの自動補完を避ける方法を探していました。これは、 "エコー"と置き換えることでオートコンプリートエントリの提供を停止します。私はローカル支店の自動完成をしたいと思います。 –

+0

@GalderZamarreño私のzshの知識の範囲を超えていることを恐れる; zshリストを試してみるかもしれません。彼らは役に立つ人のように見えます。 – Christopher

1

__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秒ではなく瞬時に完了します。

1

あなたがタグの束を参照してください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_programremote-branch-refs-noprefixを定義するために使用されるかを見ることができます。この定義をgit-checkoutの場合に変更したいと考えています。

zstyle ':completion::complete:git-checkout:argument-rest:remote-branch-refs-noprefix' command "echo" 
関連する問題