Subject: Re: [PATCH 2/2] completion: Use parse-options raw output for simple long options

From: Jonathan Nieder <[email-masked]>
Date: Wed, 11 Apr 2012 08:09:24 -0500

Stephen Boyd wrote:

> Is there some way to compute these lists with some magical function instead
> of duplicating that logic over and over?

Maybe roughly like this.

	for command in $porcelain
	do
		eval "__git_${command//-/_}_options="
	done
	__git_complete_for_command ()
	{
		local options
		local options_var="__git_${command//-/_}_options"

		eval "options=\$$options_var"
		if test -z "$options"
		then
			eval "$options_var=\$(__git_list_command_options \$command)"
			eval "options=\$$options_var"
		fi

		...
	}

	_git () {
		...
		__git_complete_for_command "$command"
	}

Jonathan