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

Re: [PATCH] Add shell completion for git remote rm

From
Todd Zullinger <tmz@pobox.com>
Date
Dec 30, 2017, 00:52 UTC
Message-ID
<20171230005222.GT3693@zaya.teonanacatl.net>
In-Reply-To
<87y3ll6s0e.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 14 quoted lines
>> I think adding 'rm' to completion definitely counts as advertisement.
>> It doesn't have much practical use, after all: typing 'rm' with
>> completion is actually one more keystroke than without (r<TAB>m vs. rm).
> 
> This is only one use of the completion interface, maybe you only use it
> like that, but not everyone does.
> 
> The completion interface has two uses, one is to actually save you
> typing, the other is subcommand discovery, and maybe someone who has a
> use neither you or I have thought of is about to point out a third.
> 
> I'll type "git $whatever $subcommand<TAB>" as *validation* that I've
> found the right command, not to complete it for me. This is a thing
> that's in my muscle memory for everything.

Is that meant to be in favor of including rm in the completion results or against? :)

Show 29 quoted lines
> Since I've been typing "git remote rm<TAB>" for a while (started before
> this deprecation happened) I've actually been meaning to submit
> completion for "rm" since it works, not knowing about Duy's patch until
> now.
> 
> Now, even if someone disagrees that we should have "rm" at all I think
> that in general we should not conflate two different things, one is
> whether:
> 
>     git remote <TAB>
> 
> shows both "rm" and "remove" in the list, and the other is whether:
> 
>     git remote rm<TAB>
> 
> Should yield:
> 
>     git remote rm<SPACE>
> 
> Or, as now happens:
> 
>     git remote rm<NOTHING AND ÆVAR THINKS IT'S BROKEN>
> 
> I can see why we'd, in general, we'd like to not advertise certain
> options for completion (due to deprecation, or just to avoid verbosity),
> but complete them once they're unambiguously typed out.
> 
> I don't know whether the bash completion interface supports making that
> distinction, but it would be useful.

It can be done, though I think that it's probably better to subtly lead people to use 'git remote remove' going forward, to keep things consistent. I don't have a strong preference for or against the rm -> remove change, but since that's been done I think there's a benefit to keeping things consistent in the UI. And I think that should also apply to not offering completion for commands/subcommands/options which are only kept for backward compatibility.

Here's one way to make 'git remote rm <TAB>' work without including it in the output of 'git remote <TAB>':

diff --git i/contrib/completion/git-completion.bash w/contrib/completion/git-completion.bash
index 3683c772c5..aa63f028ab 100644
--- i/contrib/completion/git-completion.bash
+++ w/contrib/completion/git-completion.bash
@@ -2668,7 +2668,9 @@ _git_remote ()
 		add rename remove set-head set-branches
 		get-url set-url show prune update
 		"
-	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+	# Don't advertise rm by including it in subcommands, but complete
+	# remotes if it is used.
+	local subcommand="$(__git_find_on_cmdline "$subcommands rm")"
 	if [ -z "$subcommand" ]; then
 		case "$cur" in
 		--*)

Keeping 'git remote rm' working to avoid breaking scripts is
one thing, but having it in the completion code makes it
more likely that it will continue to be seen as a
recommended subcommand.

This leads to patches like this one, where it's presumed
that the lack of completion is simply an oversight or a bug.
Of course, the lack of completion hasn't caused everyone to
forget that 'remote rm' was changed to 'remote remove', so
that reasoning may be full of hot air (or worse). ;)

The current result of 'git remote rm <TAB>' isn't so great.
It's arguably worse to have it pretend that no subcommand
was given than to list the remotes.

$ git remote rm <TAB>
add            remove         set-head       update
get-url        rename         set-url
prune          set-branches   show

I think completing nothing or completing the remotes
(without offering rm in the subcommand list) would be
better, after looking at it a bit.

I don't know how to disable file completion, but I'm not
intimately familiar with the git completion script (thanks
to it working so damn well).  I'm guessing there's a way to
do that, if there's a strong desire to not complete the
remotes at all.

I don't think we should include rm in 'git remote <TAB>'
completion, but I don't care much either way what 'git
remote rm <TAB>' includes.  But it should be better than
including the other subcommands.
-- 
Todd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There, I've gone and soiled myself, are you happy now?!
    -- Stewie Griffin
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 9 of 23 in “Add shell completion for git remote rm”
  1. Add shell completion for git remote rmKeith Smiley, Dec 29, 2017
  2. Todd ZullingerDec 29, 2017
  3. Keith SmileyDec 29, 2017
  4. Todd ZullingerDec 29, 2017
  5. Keith SmileyDec 29, 2017
  6. SZEDER GáborDec 29, 2017
  7. Keith SmileyDec 29, 2017
  8. Ævar Arnfjörð BjarmasonDec 29, 2017
  9. Todd ZullingerDec 30, 2017
  10. Ævar Arnfjörð BjarmasonDec 30, 2017
  11. Keith SmileyDec 31, 2017
  12. Junio C HamanoJan 3, 2018
  13. Keith SmileyJan 15, 2018
  14. Duy NguyenJan 16, 2018
  15. Junio C HamanoJan 16, 2018
  16. Duy NguyenJan 17, 2018
  17. Kevin DaudtJan 17, 2018
  18. Duy NguyenJan 17, 2018
  19. Keith SmileyJul 16, 2018
  20. Junio C HamanoJan 17, 2018
  21. Duy NguyenJan 1, 2018
  22. Kevin DaudtDec 29, 2017
  23. Keith SmileyDec 29, 2017

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.