Re: [PATCH 3/3] completion: improve shell expansion of items
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- Sep 27, 2012, 00:37 UTC
- Message-ID
- <20120927003751.GI10144@goldbirke>
- In-Reply-To
- <20120926215119.GC18653@sigill.intra.peff.net>
Hi,
On Wed, Sep 26, 2012 at 05:51:19PM -0400, Jeff King wrote:
Show 29 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index be800e0..b0416ea 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -225,6 +225,18 @@ fi
> fi
> fi
>
> +# Quotes each element of an IFS-delimited list for shell reuse
> +__git_quote()
> +{
> + local i
> + local delim
> + for i in $1; do
> + local quoted=${i//\'/\'\\\'\'}
> + printf "${delim:+$IFS}'%s'" "$quoted"
> + delim=t
> + done
> +}
> +
> # Generates completion reply with compgen, appending a space to possible
> # completion words, if necessary.
> # It accepts 1 to 4 arguments:
> @@ -261,7 +273,7 @@ __gitcomp_nl ()
> __gitcomp_nl ()
> {
> local IFS=$'\n'
> - COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
> + COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$(__git_quote "$1")" -- "${3-$cur}"))Iterating through all possible completion words undermines the main reason for __gitcomp_nl()'s existence: to handle potentially large number of possible completion words faster than the old __gitcomp(). If we really have to iterate in a subshell, then it would perhaps be better to drop __gitcomp_nl(), go back to using __gitcomp(), and modify that instead.
After all, anyone could drop a file called git-cmd-${meta} on his $PATH, and then get cmd- offered, because completion of git commands still goes through __gitcomp().