Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add gifast plugin

Using the upstream git completion and prompt stuff.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
  • Loading branch information...
commit 5a11228e93c667dd6d1cc87ec385ddf39d9e4726 1 parent c2ae9e0
Felipe Contreras authored
78  plugins/gitfast/_git
... ...
@@ -0,0 +1,78 @@
  1
+#compdef git gitk
  2
+
  3
+# zsh completion wrapper for git
  4
+#
  5
+# You need git's bash completion script installed somewhere, by default on the
  6
+# same directory as this script.
  7
+#
  8
+# If your script is on ~/.git-completion.sh instead, you can configure it on
  9
+# your ~/.zshrc:
  10
+#
  11
+#  zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
  12
+#
  13
+# The recommended way to install this script is to copy to
  14
+# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
  15
+#
  16
+#  fpath=(~/.zsh/completion $fpath)
  17
+
  18
+complete ()
  19
+{
  20
+	# do nothing
  21
+	return 0
  22
+}
  23
+
  24
+zstyle -s ":completion:*:*:git:*" script script
  25
+test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
  26
+ZSH_VERSION='' . "$script"
  27
+
  28
+__gitcomp ()
  29
+{
  30
+	emulate -L zsh
  31
+
  32
+	local cur_="${3-$cur}"
  33
+
  34
+	case "$cur_" in
  35
+	--*=)
  36
+		;;
  37
+	*)
  38
+		local c IFS=$' \t\n'
  39
+		local -a array
  40
+		for c in ${=1}; do
  41
+			c="$c${4-}"
  42
+			case $c in
  43
+			--*=*|*.) ;;
  44
+			*) c="$c " ;;
  45
+			esac
  46
+			array+=("$c")
  47
+		done
  48
+		compset -P '*[=:]'
  49
+		compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
  50
+		;;
  51
+	esac
  52
+}
  53
+
  54
+__gitcomp_nl ()
  55
+{
  56
+	emulate -L zsh
  57
+
  58
+	local IFS=$'\n'
  59
+	compset -P '*[=:]'
  60
+	compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  61
+}
  62
+
  63
+_git ()
  64
+{
  65
+	local _ret=1
  66
+	() {
  67
+		emulate -L ksh
  68
+		local cur cword prev
  69
+		cur=${words[CURRENT-1]}
  70
+		prev=${words[CURRENT-2]}
  71
+		let cword=CURRENT-1
  72
+		__${service}_main
  73
+	}
  74
+	let _ret && _default -S '' && _ret=0
  75
+	return _ret
  76
+}
  77
+
  78
+_git
2,483  plugins/gitfast/git-completion.bash
... ...
@@ -0,0 +1,2483 @@
  1
+#!bash
  2
+#
  3
+# bash/zsh completion support for core Git.
  4
+#
  5
+# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
  6
+# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
  7
+# Distributed under the GNU General Public License, version 2.0.
  8
+#
  9
+# The contained completion routines provide support for completing:
  10
+#
  11
+#    *) local and remote branch names
  12
+#    *) local and remote tag names
  13
+#    *) .git/remotes file names
  14
+#    *) git 'subcommands'
  15
+#    *) tree paths within 'ref:path/to/file' expressions
  16
+#    *) common --long-options
  17
+#
  18
+# To use these routines:
  19
+#
  20
+#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
  21
+#    2) Add the following line to your .bashrc/.zshrc:
  22
+#        source ~/.git-completion.sh
  23
+#    3) Consider changing your PS1 to also show the current branch,
  24
+#       see git-prompt.sh for details.
  25
+
  26
+if [[ -n ${ZSH_VERSION-} ]]; then
  27
+	autoload -U +X bashcompinit && bashcompinit
  28
+fi
  29
+
  30
+case "$COMP_WORDBREAKS" in
  31
+*:*) : great ;;
  32
+*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
  33
+esac
  34
+
  35
+# __gitdir accepts 0 or 1 arguments (i.e., location)
  36
+# returns location of .git repo
  37
+__gitdir ()
  38
+{
  39
+	# Note: this function is duplicated in git-prompt.sh
  40
+	# When updating it, make sure you update the other one to match.
  41
+	if [ -z "${1-}" ]; then
  42
+		if [ -n "${__git_dir-}" ]; then
  43
+			echo "$__git_dir"
  44
+		elif [ -n "${GIT_DIR-}" ]; then
  45
+			test -d "${GIT_DIR-}" || return 1
  46
+			echo "$GIT_DIR"
  47
+		elif [ -d .git ]; then
  48
+			echo .git
  49
+		else
  50
+			git rev-parse --git-dir 2>/dev/null
  51
+		fi
  52
+	elif [ -d "$1/.git" ]; then
  53
+		echo "$1/.git"
  54
+	else
  55
+		echo "$1"
  56
+	fi
  57
+}
  58
+
  59
+__gitcomp_1 ()
  60
+{
  61
+	local c IFS=$' \t\n'
  62
+	for c in $1; do
  63
+		c="$c$2"
  64
+		case $c in
  65
+		--*=*|*.) ;;
  66
+		*) c="$c " ;;
  67
+		esac
  68
+		printf '%s\n' "$c"
  69
+	done
  70
+}
  71
+
  72
+# The following function is based on code from:
  73
+#
  74
+#   bash_completion - programmable completion functions for bash 3.2+
  75
+#
  76
+#   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
  77
+#             © 2009-2010, Bash Completion Maintainers
  78
+#                     <bash-completion-devel@lists.alioth.debian.org>
  79
+#
  80
+#   This program is free software; you can redistribute it and/or modify
  81
+#   it under the terms of the GNU General Public License as published by
  82
+#   the Free Software Foundation; either version 2, or (at your option)
  83
+#   any later version.
  84
+#
  85
+#   This program is distributed in the hope that it will be useful,
  86
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
  87
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  88
+#   GNU General Public License for more details.
  89
+#
  90
+#   You should have received a copy of the GNU General Public License
  91
+#   along with this program; if not, write to the Free Software Foundation,
  92
+#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  93
+#
  94
+#   The latest version of this software can be obtained here:
  95
+#
  96
+#   http://bash-completion.alioth.debian.org/
  97
+#
  98
+#   RELEASE: 2.x
  99
+
  100
+# This function can be used to access a tokenized list of words
  101
+# on the command line:
  102
+#
  103
+#	__git_reassemble_comp_words_by_ref '=:'
  104
+#	if test "${words_[cword_-1]}" = -w
  105
+#	then
  106
+#		...
  107
+#	fi
  108
+#
  109
+# The argument should be a collection of characters from the list of
  110
+# word completion separators (COMP_WORDBREAKS) to treat as ordinary
  111
+# characters.
  112
+#
  113
+# This is roughly equivalent to going back in time and setting
  114
+# COMP_WORDBREAKS to exclude those characters.  The intent is to
  115
+# make option types like --date=<type> and <rev>:<path> easy to
  116
+# recognize by treating each shell word as a single token.
  117
+#
  118
+# It is best not to set COMP_WORDBREAKS directly because the value is
  119
+# shared with other completion scripts.  By the time the completion
  120
+# function gets called, COMP_WORDS has already been populated so local
  121
+# changes to COMP_WORDBREAKS have no effect.
  122
+#
  123
+# Output: words_, cword_, cur_.
  124
+
  125
+__git_reassemble_comp_words_by_ref()
  126
+{
  127
+	local exclude i j first
  128
+	# Which word separators to exclude?
  129
+	exclude="${1//[^$COMP_WORDBREAKS]}"
  130
+	cword_=$COMP_CWORD
  131
+	if [ -z "$exclude" ]; then
  132
+		words_=("${COMP_WORDS[@]}")
  133
+		return
  134
+	fi
  135
+	# List of word completion separators has shrunk;
  136
+	# re-assemble words to complete.
  137
+	for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
  138
+		# Append each nonempty word consisting of just
  139
+		# word separator characters to the current word.
  140
+		first=t
  141
+		while
  142
+			[ $i -gt 0 ] &&
  143
+			[ -n "${COMP_WORDS[$i]}" ] &&
  144
+			# word consists of excluded word separators
  145
+			[ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
  146
+		do
  147
+			# Attach to the previous token,
  148
+			# unless the previous token is the command name.
  149
+			if [ $j -ge 2 ] && [ -n "$first" ]; then
  150
+				((j--))
  151
+			fi
  152
+			first=
  153
+			words_[$j]=${words_[j]}${COMP_WORDS[i]}
  154
+			if [ $i = $COMP_CWORD ]; then
  155
+				cword_=$j
  156
+			fi
  157
+			if (($i < ${#COMP_WORDS[@]} - 1)); then
  158
+				((i++))
  159
+			else
  160
+				# Done.
  161
+				return
  162
+			fi
  163
+		done
  164
+		words_[$j]=${words_[j]}${COMP_WORDS[i]}
  165
+		if [ $i = $COMP_CWORD ]; then
  166
+			cword_=$j
  167
+		fi
  168
+	done
  169
+}
  170
+
  171
+if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
  172
+if [[ -z ${ZSH_VERSION:+set} ]]; then
  173
+_get_comp_words_by_ref ()
  174
+{
  175
+	local exclude cur_ words_ cword_
  176
+	if [ "$1" = "-n" ]; then
  177
+		exclude=$2
  178
+		shift 2
  179
+	fi
  180
+	__git_reassemble_comp_words_by_ref "$exclude"
  181
+	cur_=${words_[cword_]}
  182
+	while [ $# -gt 0 ]; do
  183
+		case "$1" in
  184
+		cur)
  185
+			cur=$cur_
  186
+			;;
  187
+		prev)
  188
+			prev=${words_[$cword_-1]}
  189
+			;;
  190
+		words)
  191
+			words=("${words_[@]}")
  192
+			;;
  193
+		cword)
  194
+			cword=$cword_
  195
+			;;
  196
+		esac
  197
+		shift
  198
+	done
  199
+}
  200
+else
  201
+_get_comp_words_by_ref ()
  202
+{
  203
+	while [ $# -gt 0 ]; do
  204
+		case "$1" in
  205
+		cur)
  206
+			cur=${COMP_WORDS[COMP_CWORD]}
  207
+			;;
  208
+		prev)
  209
+			prev=${COMP_WORDS[COMP_CWORD-1]}
  210
+			;;
  211
+		words)
  212
+			words=("${COMP_WORDS[@]}")
  213
+			;;
  214
+		cword)
  215
+			cword=$COMP_CWORD
  216
+			;;
  217
+		-n)
  218
+			# assume COMP_WORDBREAKS is already set sanely
  219
+			shift
  220
+			;;
  221
+		esac
  222
+		shift
  223
+	done
  224
+}
  225
+fi
  226
+fi
  227
+
  228
+# Generates completion reply with compgen, appending a space to possible
  229
+# completion words, if necessary.
  230
+# It accepts 1 to 4 arguments:
  231
+# 1: List of possible completion words.
  232
+# 2: A prefix to be added to each possible completion word (optional).
  233
+# 3: Generate possible completion matches for this word (optional).
  234
+# 4: A suffix to be appended to each possible completion word (optional).
  235
+__gitcomp ()
  236
+{
  237
+	local cur_="${3-$cur}"
  238
+
  239
+	case "$cur_" in
  240
+	--*=)
  241
+		COMPREPLY=()
  242
+		;;
  243
+	*)
  244
+		local IFS=$'\n'
  245
+		COMPREPLY=($(compgen -P "${2-}" \
  246
+			-W "$(__gitcomp_1 "${1-}" "${4-}")" \
  247
+			-- "$cur_"))
  248
+		;;
  249
+	esac
  250
+}
  251
+
  252
+# Generates completion reply with compgen from newline-separated possible
  253
+# completion words by appending a space to all of them.
  254
+# It accepts 1 to 4 arguments:
  255
+# 1: List of possible completion words, separated by a single newline.
  256
+# 2: A prefix to be added to each possible completion word (optional).
  257
+# 3: Generate possible completion matches for this word (optional).
  258
+# 4: A suffix to be appended to each possible completion word instead of
  259
+#    the default space (optional).  If specified but empty, nothing is
  260
+#    appended.
  261
+__gitcomp_nl ()
  262
+{
  263
+	local IFS=$'\n'
  264
+	COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
  265
+}
  266
+
  267
+__git_heads ()
  268
+{
  269
+	local dir="$(__gitdir)"
  270
+	if [ -d "$dir" ]; then
  271
+		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  272
+			refs/heads
  273
+		return
  274
+	fi
  275
+}
  276
+
  277
+__git_tags ()
  278
+{
  279
+	local dir="$(__gitdir)"
  280
+	if [ -d "$dir" ]; then
  281
+		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
  282
+			refs/tags
  283
+		return
  284
+	fi
  285
+}
  286
+
  287
+# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
  288
+# presence of 2nd argument means use the guess heuristic employed
  289
+# by checkout for tracking branches
  290
+__git_refs ()
  291
+{
  292
+	local i hash dir="$(__gitdir "${1-}")" track="${2-}"
  293
+	local format refs
  294
+	if [ -d "$dir" ]; then
  295
+		case "$cur" in
  296
+		refs|refs/*)
  297
+			format="refname"
  298
+			refs="${cur%/*}"
  299
+			track=""
  300
+			;;
  301
+		*)
  302
+			for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
  303
+				if [ -e "$dir/$i" ]; then echo $i; fi
  304
+			done
  305
+			format="refname:short"
  306
+			refs="refs/tags refs/heads refs/remotes"
  307
+			;;
  308
+		esac
  309
+		git --git-dir="$dir" for-each-ref --format="%($format)" \
  310
+			$refs
  311
+		if [ -n "$track" ]; then
  312
+			# employ the heuristic used by git checkout
  313
+			# Try to find a remote branch that matches the completion word
  314
+			# but only output if the branch name is unique
  315
+			local ref entry
  316
+			git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
  317
+				"refs/remotes/" | \
  318
+			while read -r entry; do
  319
+				eval "$entry"
  320
+				ref="${ref#*/}"
  321
+				if [[ "$ref" == "$cur"* ]]; then
  322
+					echo "$ref"
  323
+				fi
  324
+			done | uniq -u
  325
+		fi
  326
+		return
  327
+	fi
  328
+	case "$cur" in
  329
+	refs|refs/*)
  330
+		git ls-remote "$dir" "$cur*" 2>/dev/null | \
  331
+		while read -r hash i; do
  332
+			case "$i" in
  333
+			*^{}) ;;
  334
+			*) echo "$i" ;;
  335
+			esac
  336
+		done
  337
+		;;
  338
+	*)
  339
+		git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
  340
+		while read -r hash i; do
  341
+			case "$i" in
  342
+			*^{}) ;;
  343
+			refs/*) echo "${i#refs/*/}" ;;
  344
+			*) echo "$i" ;;
  345
+			esac
  346
+		done
  347
+		;;
  348
+	esac
  349
+}
  350
+
  351
+# __git_refs2 requires 1 argument (to pass to __git_refs)
  352
+__git_refs2 ()
  353
+{
  354
+	local i
  355
+	for i in $(__git_refs "$1"); do
  356
+		echo "$i:$i"
  357
+	done
  358
+}
  359
+
  360
+# __git_refs_remotes requires 1 argument (to pass to ls-remote)
  361
+__git_refs_remotes ()
  362
+{
  363
+	local i hash
  364
+	git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
  365
+	while read -r hash i; do
  366
+		echo "$i:refs/remotes/$1/${i#refs/heads/}"
  367
+	done
  368
+}
  369
+
  370
+__git_remotes ()
  371
+{
  372
+	local i IFS=$'\n' d="$(__gitdir)"
  373
+	test -d "$d/remotes" && ls -1 "$d/remotes"
  374
+	for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
  375
+		i="${i#remote.}"
  376
+		echo "${i/.url*/}"
  377
+	done
  378
+}
  379
+
  380
+__git_list_merge_strategies ()
  381
+{
  382
+	git merge -s help 2>&1 |
  383
+	sed -n -e '/[Aa]vailable strategies are: /,/^$/{
  384
+		s/\.$//
  385
+		s/.*://
  386
+		s/^[ 	]*//
  387
+		s/[ 	]*$//
  388
+		p
  389
+	}'
  390
+}
  391
+
  392
+__git_merge_strategies=
  393
+# 'git merge -s help' (and thus detection of the merge strategy
  394
+# list) fails, unfortunately, if run outside of any git working
  395
+# tree.  __git_merge_strategies is set to the empty string in
  396
+# that case, and the detection will be repeated the next time it
  397
+# is needed.
  398
+__git_compute_merge_strategies ()
  399
+{
  400
+	test -n "$__git_merge_strategies" ||
  401
+	__git_merge_strategies=$(__git_list_merge_strategies)
  402
+}
  403
+
  404
+__git_complete_revlist_file ()
  405
+{
  406
+	local pfx ls ref cur_="$cur"
  407
+	case "$cur_" in
  408
+	*..?*:*)
  409
+		return
  410
+		;;
  411
+	?*:*)
  412
+		ref="${cur_%%:*}"
  413
+		cur_="${cur_#*:}"
  414
+		case "$cur_" in
  415
+		?*/*)
  416
+			pfx="${cur_%/*}"
  417
+			cur_="${cur_##*/}"
  418
+			ls="$ref:$pfx"
  419
+			pfx="$pfx/"
  420
+			;;
  421
+		*)
  422
+			ls="$ref"
  423
+			;;
  424
+		esac
  425
+
  426
+		case "$COMP_WORDBREAKS" in
  427
+		*:*) : great ;;
  428
+		*)   pfx="$ref:$pfx" ;;
  429
+		esac
  430
+
  431
+		__gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
  432
+				| sed '/^100... blob /{
  433
+				           s,^.*	,,
  434
+				           s,$, ,
  435
+				       }
  436
+				       /^120000 blob /{
  437
+				           s,^.*	,,
  438
+				           s,$, ,
  439
+				       }
  440
+				       /^040000 tree /{
  441
+				           s,^.*	,,
  442
+				           s,$,/,
  443
+				       }
  444
+				       s/^.*	//')" \
  445
+			"$pfx" "$cur_" ""
  446
+		;;
  447
+	*...*)
  448
+		pfx="${cur_%...*}..."
  449
+		cur_="${cur_#*...}"
  450
+		__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  451
+		;;
  452
+	*..*)
  453
+		pfx="${cur_%..*}.."
  454
+		cur_="${cur_#*..}"
  455
+		__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  456
+		;;
  457
+	*)
  458
+		__gitcomp_nl "$(__git_refs)"
  459
+		;;
  460
+	esac
  461
+}
  462
+
  463
+
  464
+__git_complete_file ()
  465
+{
  466
+	__git_complete_revlist_file
  467
+}
  468
+
  469
+__git_complete_revlist ()
  470
+{
  471
+	__git_complete_revlist_file
  472
+}
  473
+
  474
+__git_complete_remote_or_refspec ()
  475
+{
  476
+	local cur_="$cur" cmd="${words[1]}"
  477
+	local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
  478
+	if [ "$cmd" = "remote" ]; then
  479
+		((c++))
  480
+	fi
  481
+	while [ $c -lt $cword ]; do
  482
+		i="${words[c]}"
  483
+		case "$i" in
  484
+		--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
  485
+		--all)
  486
+			case "$cmd" in
  487
+			push) no_complete_refspec=1 ;;
  488
+			fetch)
  489
+				COMPREPLY=()
  490
+				return
  491
+				;;
  492
+			*) ;;
  493
+			esac
  494
+			;;
  495
+		-*) ;;
  496
+		*) remote="$i"; break ;;
  497
+		esac
  498
+		((c++))
  499
+	done
  500
+	if [ -z "$remote" ]; then
  501
+		__gitcomp_nl "$(__git_remotes)"
  502
+		return
  503
+	fi
  504
+	if [ $no_complete_refspec = 1 ]; then
  505
+		COMPREPLY=()
  506
+		return
  507
+	fi
  508
+	[ "$remote" = "." ] && remote=
  509
+	case "$cur_" in
  510
+	*:*)
  511
+		case "$COMP_WORDBREAKS" in
  512
+		*:*) : great ;;
  513
+		*)   pfx="${cur_%%:*}:" ;;
  514
+		esac
  515
+		cur_="${cur_#*:}"
  516
+		lhs=0
  517
+		;;
  518
+	+*)
  519
+		pfx="+"
  520
+		cur_="${cur_#+}"
  521
+		;;
  522
+	esac
  523
+	case "$cmd" in
  524
+	fetch)
  525
+		if [ $lhs = 1 ]; then
  526
+			__gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
  527
+		else
  528
+			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  529
+		fi
  530
+		;;
  531
+	pull|remote)
  532
+		if [ $lhs = 1 ]; then
  533
+			__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
  534
+		else
  535
+			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  536
+		fi
  537
+		;;
  538
+	push)
  539
+		if [ $lhs = 1 ]; then
  540
+			__gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
  541
+		else
  542
+			__gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
  543
+		fi
  544
+		;;
  545
+	esac
  546
+}
  547
+
  548
+__git_complete_strategy ()
  549
+{
  550
+	__git_compute_merge_strategies
  551
+	case "$prev" in
  552
+	-s|--strategy)
  553
+		__gitcomp "$__git_merge_strategies"
  554
+		return 0
  555
+	esac
  556
+	case "$cur" in
  557
+	--strategy=*)
  558
+		__gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
  559
+		return 0
  560
+		;;
  561
+	esac
  562
+	return 1
  563
+}
  564
+
  565
+__git_list_all_commands ()
  566
+{
  567
+	local i IFS=" "$'\n'
  568
+	for i in $(git help -a|egrep '^  [a-zA-Z0-9]')
  569
+	do
  570
+		case $i in
  571
+		*--*)             : helper pattern;;
  572
+		*) echo $i;;
  573
+		esac
  574
+	done
  575
+}
  576
+
  577
+__git_all_commands=
  578
+__git_compute_all_commands ()
  579
+{
  580
+	test -n "$__git_all_commands" ||
  581
+	__git_all_commands=$(__git_list_all_commands)
  582
+}
  583
+
  584
+__git_list_porcelain_commands ()
  585
+{
  586
+	local i IFS=" "$'\n'
  587
+	__git_compute_all_commands
  588
+	for i in "help" $__git_all_commands
  589
+	do
  590
+		case $i in
  591
+		*--*)             : helper pattern;;
  592
+		applymbox)        : ask gittus;;
  593
+		applypatch)       : ask gittus;;
  594
+		archimport)       : import;;
  595
+		cat-file)         : plumbing;;
  596
+		check-attr)       : plumbing;;
  597
+		check-ref-format) : plumbing;;
  598
+		checkout-index)   : plumbing;;
  599
+		commit-tree)      : plumbing;;
  600
+		count-objects)    : infrequent;;
  601
+		credential-cache) : credentials helper;;
  602
+		credential-store) : credentials helper;;
  603
+		cvsexportcommit)  : export;;
  604
+		cvsimport)        : import;;
  605
+		cvsserver)        : daemon;;
  606
+		daemon)           : daemon;;
  607
+		diff-files)       : plumbing;;
  608
+		diff-index)       : plumbing;;
  609
+		diff-tree)        : plumbing;;
  610
+		fast-import)      : import;;
  611
+		fast-export)      : export;;
  612
+		fsck-objects)     : plumbing;;
  613
+		fetch-pack)       : plumbing;;
  614
+		fmt-merge-msg)    : plumbing;;
  615
+		for-each-ref)     : plumbing;;
  616
+		hash-object)      : plumbing;;
  617
+		http-*)           : transport;;
  618
+		index-pack)       : plumbing;;
  619
+		init-db)          : deprecated;;
  620
+		local-fetch)      : plumbing;;
  621
+		lost-found)       : infrequent;;
  622
+		ls-files)         : plumbing;;
  623
+		ls-remote)        : plumbing;;
  624
+		ls-tree)          : plumbing;;
  625
+		mailinfo)         : plumbing;;
  626
+		mailsplit)        : plumbing;;
  627
+		merge-*)          : plumbing;;
  628
+		mktree)           : plumbing;;
  629
+		mktag)            : plumbing;;
  630
+		pack-objects)     : plumbing;;
  631
+		pack-redundant)   : plumbing;;
  632
+		pack-refs)        : plumbing;;
  633
+		parse-remote)     : plumbing;;
  634
+		patch-id)         : plumbing;;
  635
+		peek-remote)      : plumbing;;
  636
+		prune)            : plumbing;;
  637
+		prune-packed)     : plumbing;;
  638
+		quiltimport)      : import;;
  639
+		read-tree)        : plumbing;;
  640
+		receive-pack)     : plumbing;;
  641
+		remote-*)         : transport;;
  642
+		repo-config)      : deprecated;;
  643
+		rerere)           : plumbing;;
  644
+		rev-list)         : plumbing;;
  645
+		rev-parse)        : plumbing;;
  646
+		runstatus)        : plumbing;;
  647
+		sh-setup)         : internal;;
  648
+		shell)            : daemon;;
  649
+		show-ref)         : plumbing;;
  650
+		send-pack)        : plumbing;;
  651
+		show-index)       : plumbing;;
  652
+		ssh-*)            : transport;;
  653
+		stripspace)       : plumbing;;
  654
+		symbolic-ref)     : plumbing;;
  655
+		tar-tree)         : deprecated;;
  656
+		unpack-file)      : plumbing;;
  657
+		unpack-objects)   : plumbing;;
  658
+		update-index)     : plumbing;;
  659
+		update-ref)       : plumbing;;
  660
+		update-server-info) : daemon;;
  661
+		upload-archive)   : plumbing;;
  662
+		upload-pack)      : plumbing;;
  663
+		write-tree)       : plumbing;;
  664
+		var)              : infrequent;;
  665
+		verify-pack)      : infrequent;;
  666
+		verify-tag)       : plumbing;;
  667
+		*) echo $i;;
  668
+		esac
  669
+	done
  670
+}
  671
+
  672
+__git_porcelain_commands=
  673
+__git_compute_porcelain_commands ()
  674
+{
  675
+	__git_compute_all_commands
  676
+	test -n "$__git_porcelain_commands" ||
  677
+	__git_porcelain_commands=$(__git_list_porcelain_commands)
  678
+}
  679
+
  680
+__git_pretty_aliases ()
  681
+{
  682
+	local i IFS=$'\n'
  683
+	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
  684
+		case "$i" in
  685
+		pretty.*)
  686
+			i="${i#pretty.}"
  687
+			echo "${i/ */}"
  688
+			;;
  689
+		esac
  690
+	done
  691
+}
  692
+
  693
+__git_aliases ()
  694
+{
  695
+	local i IFS=$'\n'
  696
+	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
  697
+		case "$i" in
  698
+		alias.*)
  699
+			i="${i#alias.}"
  700
+			echo "${i/ */}"
  701
+			;;
  702
+		esac
  703
+	done
  704
+}
  705
+
  706
+# __git_aliased_command requires 1 argument
  707
+__git_aliased_command ()
  708
+{
  709
+	local word cmdline=$(git --git-dir="$(__gitdir)" \
  710
+		config --get "alias.$1")
  711
+	for word in $cmdline; do
  712
+		case "$word" in
  713
+		\!gitk|gitk)
  714
+			echo "gitk"
  715
+			return
  716
+			;;
  717
+		\!*)	: shell command alias ;;
  718
+		-*)	: option ;;
  719
+		*=*)	: setting env ;;
  720
+		git)	: git itself ;;
  721
+		*)
  722
+			echo "$word"
  723
+			return
  724
+		esac
  725
+	done
  726
+}
  727
+
  728
+# __git_find_on_cmdline requires 1 argument
  729
+__git_find_on_cmdline ()
  730
+{
  731
+	local word subcommand c=1
  732
+	while [ $c -lt $cword ]; do
  733
+		word="${words[c]}"
  734
+		for subcommand in $1; do
  735
+			if [ "$subcommand" = "$word" ]; then
  736
+				echo "$subcommand"
  737
+				return
  738
+			fi
  739
+		done
  740
+		((c++))
  741
+	done
  742
+}
  743
+
  744
+__git_has_doubledash ()
  745
+{
  746
+	local c=1
  747
+	while [ $c -lt $cword ]; do
  748
+		if [ "--" = "${words[c]}" ]; then
  749
+			return 0
  750
+		fi
  751
+		((c++))
  752
+	done
  753
+	return 1
  754
+}
  755
+
  756
+__git_whitespacelist="nowarn warn error error-all fix"
  757
+
  758
+_git_am ()
  759
+{
  760
+	local dir="$(__gitdir)"
  761
+	if [ -d "$dir"/rebase-apply ]; then
  762
+		__gitcomp "--skip --continue --resolved --abort"
  763
+		return
  764
+	fi
  765
+	case "$cur" in
  766
+	--whitespace=*)
  767
+		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  768
+		return
  769
+		;;
  770
+	--*)
  771
+		__gitcomp "
  772
+			--3way --committer-date-is-author-date --ignore-date
  773
+			--ignore-whitespace --ignore-space-change
  774
+			--interactive --keep --no-utf8 --signoff --utf8
  775
+			--whitespace= --scissors
  776
+			"
  777
+		return
  778
+	esac
  779
+	COMPREPLY=()
  780
+}
  781
+
  782
+_git_apply ()
  783
+{
  784
+	case "$cur" in
  785
+	--whitespace=*)
  786
+		__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
  787
+		return
  788
+		;;
  789
+	--*)
  790
+		__gitcomp "
  791
+			--stat --numstat --summary --check --index
  792
+			--cached --index-info --reverse --reject --unidiff-zero
  793
+			--apply --no-add --exclude=
  794
+			--ignore-whitespace --ignore-space-change
  795
+			--whitespace= --inaccurate-eof --verbose
  796
+			"
  797
+		return
  798
+	esac
  799
+	COMPREPLY=()
  800
+}
  801
+
  802
+_git_add ()
  803
+{
  804
+	__git_has_doubledash && return
  805
+
  806
+	case "$cur" in
  807
+	--*)
  808
+		__gitcomp "
  809
+			--interactive --refresh --patch --update --dry-run
  810
+			--ignore-errors --intent-to-add
  811
+			"
  812
+		return
  813
+	esac
  814
+	COMPREPLY=()
  815
+}
  816
+
  817
+_git_archive ()
  818
+{
  819
+	case "$cur" in
  820
+	--format=*)
  821
+		__gitcomp "$(git archive --list)" "" "${cur##--format=}"
  822
+		return
  823
+		;;
  824
+	--remote=*)
  825
+		__gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
  826
+		return
  827
+		;;
  828
+	--*)
  829
+		__gitcomp "
  830
+			--format= --list --verbose
  831
+			--prefix= --remote= --exec=
  832
+			"
  833
+		return
  834
+		;;
  835
+	esac
  836
+	__git_complete_file
  837
+}
  838
+
  839
+_git_bisect ()
  840
+{
  841
+	__git_has_doubledash && return
  842
+
  843
+	local subcommands="start bad good skip reset visualize replay log run"
  844
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
  845
+	if [ -z "$subcommand" ]; then
  846
+		if [ -f "$(__gitdir)"/BISECT_START ]; then
  847
+			__gitcomp "$subcommands"
  848
+		else
  849
+			__gitcomp "replay start"
  850
+		fi
  851
+		return
  852
+	fi
  853
+
  854
+	case "$subcommand" in
  855
+	bad|good|reset|skip|start)
  856
+		__gitcomp_nl "$(__git_refs)"
  857
+		;;
  858
+	*)
  859
+		COMPREPLY=()
  860
+		;;
  861
+	esac
  862
+}
  863
+
  864
+_git_branch ()
  865
+{
  866
+	local i c=1 only_local_ref="n" has_r="n"
  867
+
  868
+	while [ $c -lt $cword ]; do
  869
+		i="${words[c]}"
  870
+		case "$i" in
  871
+		-d|-m)	only_local_ref="y" ;;
  872
+		-r)	has_r="y" ;;
  873
+		esac
  874
+		((c++))
  875
+	done
  876
+
  877
+	case "$cur" in
  878
+	--set-upstream-to=*)
  879
+		__gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
  880
+		;;
  881
+	--*)
  882
+		__gitcomp "
  883
+			--color --no-color --verbose --abbrev= --no-abbrev
  884
+			--track --no-track --contains --merged --no-merged
  885
+			--set-upstream-to= --edit-description --list
  886
+			--unset-upstream
  887
+			"
  888
+		;;
  889
+	*)
  890
+		if [ $only_local_ref = "y" -a $has_r = "n" ]; then
  891
+			__gitcomp_nl "$(__git_heads)"
  892
+		else
  893
+			__gitcomp_nl "$(__git_refs)"
  894
+		fi
  895
+		;;
  896
+	esac
  897
+}
  898
+
  899
+_git_bundle ()
  900
+{
  901
+	local cmd="${words[2]}"
  902
+	case "$cword" in
  903
+	2)
  904
+		__gitcomp "create list-heads verify unbundle"
  905
+		;;
  906
+	3)
  907
+		# looking for a file
  908
+		;;
  909
+	*)
  910
+		case "$cmd" in
  911
+			create)
  912
+				__git_complete_revlist
  913
+			;;
  914
+		esac
  915
+		;;
  916
+	esac
  917
+}
  918
+
  919
+_git_checkout ()
  920
+{
  921
+	__git_has_doubledash && return
  922
+
  923
+	case "$cur" in
  924
+	--conflict=*)
  925
+		__gitcomp "diff3 merge" "" "${cur##--conflict=}"
  926
+		;;
  927
+	--*)
  928
+		__gitcomp "
  929
+			--quiet --ours --theirs --track --no-track --merge
  930
+			--conflict= --orphan --patch
  931
+			"
  932
+		;;
  933
+	*)
  934
+		# check if --track, --no-track, or --no-guess was specified
  935
+		# if so, disable DWIM mode
  936
+		local flags="--track --no-track --no-guess" track=1
  937
+		if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
  938
+			track=''
  939
+		fi
  940
+		__gitcomp_nl "$(__git_refs '' $track)"
  941
+		;;
  942
+	esac
  943
+}
  944
+
  945
+_git_cherry ()
  946
+{
  947
+	__gitcomp "$(__git_refs)"
  948
+}
  949
+
  950
+_git_cherry_pick ()
  951
+{
  952
+	case "$cur" in
  953
+	--*)
  954
+		__gitcomp "--edit --no-commit"
  955
+		;;
  956
+	*)
  957
+		__gitcomp_nl "$(__git_refs)"
  958
+		;;
  959
+	esac
  960
+}
  961
+
  962
+_git_clean ()
  963
+{
  964
+	__git_has_doubledash && return
  965
+
  966
+	case "$cur" in
  967
+	--*)
  968
+		__gitcomp "--dry-run --quiet"
  969
+		return
  970
+		;;
  971
+	esac
  972
+	COMPREPLY=()
  973
+}
  974
+
  975
+_git_clone ()
  976
+{
  977
+	case "$cur" in
  978
+	--*)
  979
+		__gitcomp "
  980
+			--local
  981
+			--no-hardlinks
  982
+			--shared
  983
+			--reference
  984
+			--quiet
  985
+			--no-checkout
  986
+			--bare
  987
+			--mirror
  988
+			--origin
  989
+			--upload-pack
  990
+			--template=
  991
+			--depth
  992
+			"
  993
+		return
  994
+		;;
  995
+	esac
  996
+	COMPREPLY=()
  997
+}
  998
+
  999
+_git_commit ()
  1000
+{
  1001
+	__git_has_doubledash && return
  1002
+
  1003
+	case "$cur" in
  1004
+	--cleanup=*)
  1005
+		__gitcomp "default strip verbatim whitespace
  1006
+			" "" "${cur##--cleanup=}"
  1007
+		return
  1008
+		;;
  1009
+	--reuse-message=*|--reedit-message=*|\
  1010
+	--fixup=*|--squash=*)
  1011
+		__gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
  1012
+		return
  1013
+		;;
  1014
+	--untracked-files=*)
  1015
+		__gitcomp "all no normal" "" "${cur##--untracked-files=}"
  1016
+		return
  1017
+		;;
  1018
+	--*)
  1019
+		__gitcomp "
  1020
+			--all --author= --signoff --verify --no-verify
  1021
+			--edit --no-edit
  1022
+			--amend --include --only --interactive
  1023
+			--dry-run --reuse-message= --reedit-message=
  1024
+			--reset-author --file= --message= --template=
  1025
+			--cleanup= --untracked-files --untracked-files=
  1026
+			--verbose --quiet --fixup= --squash=
  1027
+			"
  1028
+		return
  1029
+	esac
  1030
+	COMPREPLY=()
  1031
+}
  1032
+
  1033
+_git_describe ()
  1034
+{
  1035
+	case "$cur" in
  1036
+	--*)
  1037
+		__gitcomp "
  1038
+			--all --tags --contains --abbrev= --candidates=
  1039
+			--exact-match --debug --long --match --always
  1040
+			"
  1041
+		return
  1042
+	esac
  1043
+	__gitcomp_nl "$(__git_refs)"
  1044
+}
  1045
+
  1046
+__git_diff_common_options="--stat --numstat --shortstat --summary
  1047
+			--patch-with-stat --name-only --name-status --color
  1048
+			--no-color --color-words --no-renames --check
  1049
+			--full-index --binary --abbrev --diff-filter=
  1050
+			--find-copies-harder
  1051
+			--text --ignore-space-at-eol --ignore-space-change
  1052
+			--ignore-all-space --exit-code --quiet --ext-diff
  1053
+			--no-ext-diff
  1054
+			--no-prefix --src-prefix= --dst-prefix=
  1055
+			--inter-hunk-context=
  1056
+			--patience
  1057
+			--raw
  1058
+			--dirstat --dirstat= --dirstat-by-file
  1059
+			--dirstat-by-file= --cumulative
  1060
+"
  1061
+
  1062
+_git_diff ()
  1063
+{
  1064
+	__git_has_doubledash && return
  1065
+
  1066
+	case "$cur" in
  1067
+	--*)
  1068
+		__gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
  1069
+			--base --ours --theirs --no-index