git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC/PATCH] contrib: teach completion about git-worktree options and arguments

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 21, 2015, 17:21 UTC
Message-ID
<xmqq37zc7e2o.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAPig+cQhh7YCiirp4a1+R0bWh46JoFgVOVUCNidTWXK8uNL2Mg@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 9 quoted lines
> On Thu, Jul 23, 2015 at 4:49 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>> Complete subcommands 'add' and 'prune', as well as their respective
>> options --force, --detach, --dry-run, --verbose, and --expire. Also
>> complete 'refname' in "git worktree add [-b <newbranch>] <path>
>> <refname>".
>
> Ping[1]?
>
> [1]: http://article.gmane.org/gmane.comp.version-control.git/274526
Ping indeed?
Show 55 quoted lines
>
>> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
>> ---
>>
>> This is RFC since this is my first foray into the Git completion script,
>> and there are likely better and more idiomatic ways to accomplish this.
>>
>>  contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++++++++++
>>  1 file changed, 32 insertions(+)
>>
>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>> index c97c648..07c34ef 100644
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -2564,6 +2564,38 @@ _git_whatchanged ()
>>         _git_log
>>  }
>>
>> +_git_worktree ()
>> +{
>> +       local subcommands='add prune'
>> +       local subcommand="$(__git_find_on_cmdline "$subcommands")"
>> +       local c=2 n=0 refpos=2
>> +       if [ -z "$subcommand" ]; then
>> +               __gitcomp "$subcommands"
>> +       else
>> +               case "$subcommand,$cur" in
>> +               add,--*)
>> +                       __gitcomp "--force --detach"
>> +                       ;;
>> +               add,*)
>> +                       while [ $c -lt $cword ]; do
>> +                               case "${words[c]}" in
>> +                               --*) ;;
>> +                               -[bB]) ((refpos++)) ;;
>> +                               *) ((n++)) ;;
>> +                               esac
>> +                               ((c++))
>> +                       done
>> +                       if [ $n -eq $refpos ]; then
>> +                               __gitcomp_nl "$(__git_refs)"
>> +                       fi
>> +                       ;;
>> +               prune,--*)
>> +                       __gitcomp "--dry-run --verbose --expire"
>> +                       ;;
>> +               esac
>> +       fi
>> +}
>> +
>>  __git_main ()
>>  {
>>         local i c=1 command __git_dir
>> --
>> 2.5.0.rc3.407.g68aafd0
Previous: Eric SunshineNext: SZEDER Gábor
Message 3 of 6 in “contrib: teach completion about git-worktree options and arguments”
  1. contrib: teach completion about git-worktree options and argumentsEric Sunshine, Jul 23, 2015
  2. Eric SunshineAug 6, 2015
  3. Junio C HamanoAug 21, 2015
  4. SZEDER GáborAug 21, 2015
  5. completion: support 'git worktree'SZEDER Gábor, Aug 21, 2015
  6. Eric SunshineAug 21, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.