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

Re: [PATCHv2] completion: make compatible with zsh

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Aug 30, 2010, 14:19 UTC
Message-ID
<20100830141927.GA16495@neumann>
In-Reply-To
<1282877156-16149-1-git-send-email-lodatom@gmail.com>
Hi,
On Thu, Aug 26, 2010 at 10:45:56PM -0400, Mark Lodato wrote:
Show 6 quoted lines
> Modify git-completion.bash so that it also works with zsh when using
> bashcompinit.  In particular:
> 
> declare -F
>     Zsh doesn't have the same 'declare -F' as bash, but 'declare -f'
>     is the same, and it works just as well for our purposes.
Show 14 quoted lines
> @@ -2372,17 +2383,22 @@ _git ()
>  	fi
>  
>  	local completion_func="_git_${command//-/_}"
> -	declare -F $completion_func >/dev/null && $completion_func && return
> +	declare -f $completion_func >/dev/null && $completion_func && return
>  
>  	local expansion=$(__git_aliased_command "$command")
>  	if [ -n "$expansion" ]; then
>  		completion_func="_git_${expansion//-/_}"
> -		declare -F $completion_func >/dev/null && $completion_func
> +		declare -f $completion_func >/dev/null && $completion_func
>  	fi
>  }
I chose -F back then because it does not print the definition of the
completion function, so there is less stuff to throw away immediately.
However, the run-time difference seems to be barely measureable (i.e.
'time declare -f _git_config >/dev/null' vs. 'declare -F _git_config
 >/dev/null' sometimes shows 0.001s difference), so I'm fine with this
change.
Show 6 quoted lines
> @@ -2417,3 +2433,29 @@ if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
>  complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
>  	|| complete -o default -o nospace -F _git git.exe
>  fi
> +
> +if [[ -z $ZSH_VERSION ]]; then
-z?  I think you wanted to use -n here, like at the other places.
Nit: why "if [[ ... ]]"?  FWIW "if [ ... ]" would be enough.
Show 27 quoted lines
> +	shopt () {
> +		local option
> +		if [ $# -ne 2 ]; then
> +			echo "USAGE: $0 (-q|-s|-u) <option>" >&2
> +			return 1
> +		fi
> +		case "$2" in
> +		nullglob)
> +			option="$2"
> +			;;
> +		*)
> +			echo "$0: invalid option: $2" >&2
> +			return 1
> +		esac
> +		case "$1" in
> +		-q)	setopt | grep -q "$option" ;;
> +		-u)	unsetopt "$option" ;;
> +		-s)	setopt "$option" ;;
> +		*)
> +			echo "$0: invalid flag: $1" >&2
> +			return 1
> +		esac
> +	}
> +fi
> -- 
> 1.7.2.2
> 
Previous: Ævar Arnfjörð BjarmasonNext: Mark Lodato
Message 3 of 5 in “[PATCHv2] completion: make compatible with zsh”
  1. Mark LodatoAug 27, 2010
  2. Ævar Arnfjörð BjarmasonAug 28, 2010
  3. SZEDER GáborAug 30, 2010
  4. Mark LodatoAug 31, 2010
  5. Peter KjellerstedtAug 31, 2010

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.