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

Re: [PATCH] bash: __git_find_subcommand function

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 8, 2008, 02:23 UTC
Message-ID
<20080308022342.GY8410@spearce.org>
In-Reply-To
<1204815512-18128-1-git-send-email-szeder@ira.uka.de>
SZEDER Gbor <szeder@ira.uka.de> wrote:
Show 16 quoted lines
> This enables us to remove code duplications from completion
> functions for commands having subcommands.
> 
> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
> ---
> This function does not return the index of the subcommand found on the
> command line, which was in the $c variable previously.  However, $c was
> only used in if statements, like:
> 	if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
> 		__gitcomp "cmd1 cmd2 cmd3"
> 	fi
> To my understanding the only(?) purpose of those if statements was to
> prevent subcommands appearing again on the list of possible completions,
> when there was one already on the command line.  But [ -z $command ] is
> sufficient to detect those cases, so we can actually omit
> [ $c -eq $COMP_CWORD ].  Is it right, or am I missing something?

Yup, you understood it correctly. You found a cluster of "copy and paste programming" and I am happy to see it cleaned up. Thanks.

-- 
Shawn.
Previous: SZEDER GáborNext: SZEDER Gábor
Message 2 of 3 in “bash: __git_find_subcommand function”
  1. bash: __git_find_subcommand functionSZEDER Gábor, Mar 6, 2008
  2. Shawn O. PearceMar 8, 2008
  3. SZEDER GáborMar 10, 2008

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.