fdfc0b3cd966012c347a17b2352feb5f1574419d

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #1417 from felipec/fc-git-upstream

Add gifast plugin

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..45775021fff11011a98b90a6b8ebaa72d3d0cd9f
  4--- /dev/null
  5+++ b/plugins/gitfast/_git
  6@@ -0,0 +1,78 @@
  7+#compdef git gitk
  8+
  9+# zsh completion wrapper for git
 10+#
 11+# You need git's bash completion script installed somewhere, by default on the
 12+# same directory as this script.
 13+#
 14+# If your script is on ~/.git-completion.sh instead, you can configure it on
 15+# your ~/.zshrc:
 16+#
 17+#  zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
 18+#
 19+# The recommended way to install this script is to copy to
 20+# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
 21+#
 22+#  fpath=(~/.zsh/completion $fpath)
 23+
 24+complete ()
 25+{
 26+	# do nothing
 27+	return 0
 28+}
 29+
 30+zstyle -s ":completion:*:*:git:*" script script
 31+test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
 32+ZSH_VERSION='' . "$script"
 33+
 34+__gitcomp ()
 35+{
 36+	emulate -L zsh
 37+
 38+	local cur_="${3-$cur}"
 39+
 40+	case "$cur_" in
 41+	--*=)
 42+		;;
 43+	*)
 44+		local c IFS=$' \t\n'
 45+		local -a array
 46+		for c in ${=1}; do
 47+			c="$c${4-}"
 48+			case $c in
 49+			--*=*|*.) ;;
 50+			*) c="$c " ;;
 51+			esac
 52+			array+=("$c")
 53+		done
 54+		compset -P '*[=:]'
 55+		compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
 56+		;;
 57+	esac
 58+}
 59+
 60+__gitcomp_nl ()
 61+{
 62+	emulate -L zsh
 63+
 64+	local IFS=$'\n'
 65+	compset -P '*[=:]'
 66+	compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
 67+}
 68+
 69+_git ()
 70+{
 71+	local _ret=1
 72+	() {
 73+		emulate -L ksh
 74+		local cur cword prev
 75+		cur=${words[CURRENT-1]}
 76+		prev=${words[CURRENT-2]}
 77+		let cword=CURRENT-1
 78+		__${service}_main
 79+	}
 80+	let _ret && _default -S '' && _ret=0
 81+	return _ret
 82+}
 83+
 84+_git
 85diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash
 86new file mode 100644
 87index 0000000000000000000000000000000000000000..be800e09bdf0656951c415105e0d32ce0b0edf9e
 88--- /dev/null
 89+++ b/plugins/gitfast/git-completion.bash
 90@@ -0,0 +1,2483 @@
 91+#!bash
 92+#
 93+# bash/zsh completion support for core Git.
 94+#
 95+# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
 96+# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
 97+# Distributed under the GNU General Public License, version 2.0.
 98+#
 99+# The contained completion routines provide support for completing:
100+#
101+#    *) local and remote branch names
102+#    *) local and remote tag names
103+#    *) .git/remotes file names
104+#    *) git 'subcommands'
105+#    *) tree paths within 'ref:path/to/file' expressions
106+#    *) common --long-options
107+#
108+# To use these routines:
109+#
110+#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
111+#    2) Add the following line to your .bashrc/.zshrc:
112+#        source ~/.git-completion.sh
113+#    3) Consider changing your PS1 to also show the current branch,
114+#       see git-prompt.sh for details.
115+
116+if [[ -n ${ZSH_VERSION-} ]]; then
117+	autoload -U +X bashcompinit && bashcompinit
118+fi
119+
120+case "$COMP_WORDBREAKS" in
121+*:*) : great ;;
122+*)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
123+esac
124+
125+# __gitdir accepts 0 or 1 arguments (i.e., location)
126+# returns location of .git repo
127+__gitdir ()
128+{
129+	# Note: this function is duplicated in git-prompt.sh
130+	# When updating it, make sure you update the other one to match.
131+	if [ -z "${1-}" ]; then
132+		if [ -n "${__git_dir-}" ]; then
133+			echo "$__git_dir"
134+		elif [ -n "${GIT_DIR-}" ]; then
135+			test -d "${GIT_DIR-}" || return 1
136+			echo "$GIT_DIR"
137+		elif [ -d .git ]; then
138+			echo .git
139+		else
140+			git rev-parse --git-dir 2>/dev/null
141+		fi
142+	elif [ -d "$1/.git" ]; then
143+		echo "$1/.git"
144+	else
145+		echo "$1"
146+	fi
147+}
148+
149+__gitcomp_1 ()
150+{
151+	local c IFS=$' \t\n'
152+	for c in $1; do
153+		c="$c$2"
154+		case $c in
155+		--*=*|*.) ;;
156+		*) c="$c " ;;
157+		esac
158+		printf '%s\n' "$c"
159+	done
160+}
161+
162+# The following function is based on code from:
163+#
164+#   bash_completion - programmable completion functions for bash 3.2+
165+#
166+#   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
167+#             © 2009-2010, Bash Completion Maintainers
168+#                     <bash-completion-devel@lists.alioth.debian.org>
169+#
170+#   This program is free software; you can redistribute it and/or modify
171+#   it under the terms of the GNU General Public License as published by
172+#   the Free Software Foundation; either version 2, or (at your option)
173+#   any later version.
174+#
175+#   This program is distributed in the hope that it will be useful,
176+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
177+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178+#   GNU General Public License for more details.
179+#
180+#   You should have received a copy of the GNU General Public License
181+#   along with this program; if not, write to the Free Software Foundation,
182+#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
183+#
184+#   The latest version of this software can be obtained here:
185+#
186+#   http://bash-completion.alioth.debian.org/
187+#
188+#   RELEASE: 2.x
189+
190diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
191new file mode 100644
192index 0000000000000000000000000000000000000000..bf20491ec33e467f6b9591d94a2e27bc9e3d93e9
193--- /dev/null
194+++ b/plugins/gitfast/git-prompt.sh
195@@ -0,0 +1,290 @@
196+# bash/zsh git prompt support
197+#
198+# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
199+# Distributed under the GNU General Public License, version 2.0.
200+#
201+# This script allows you to see the current branch in your prompt.
202+#
203+# To enable:
204+#
205+#    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
206+#    2) Add the following line to your .bashrc/.zshrc:
207+#        source ~/.git-prompt.sh
208+#    3) Change your PS1 to also show the current branch:
209+#         Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
210+#         ZSH:  PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
211+#
212+# The argument to __git_ps1 will be displayed only if you are currently
213+# in a git repository.  The %s token will be the name of the current
214+# branch.
215+#
216+# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
217+# unstaged (*) and staged (+) changes will be shown next to the branch
218+# name.  You can configure this per-repository with the
219+# bash.showDirtyState variable, which defaults to true once
220+# GIT_PS1_SHOWDIRTYSTATE is enabled.
221+#
222+# You can also see if currently something is stashed, by setting
223+# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
224+# then a '$' will be shown next to the branch name.
225+#
226+# If you would like to see if there're untracked files, then you can set
227+# GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
228+# files, then a '%' will be shown next to the branch name.
229+#
230+# If you would like to see the difference between HEAD and its upstream,
231+# set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates you are behind, ">"
232+# indicates you are ahead, "<>" indicates you have diverged and "="
233+# indicates that there is no difference. You can further control
234+# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list
235+# of values:
236+#
237+#     verbose       show number of commits ahead/behind (+/-) upstream
238+#     legacy        don't use the '--count' option available in recent
239+#                   versions of git-rev-list
240+#     git           always compare HEAD to @{upstream}
241+#     svn           always compare HEAD to your SVN upstream
242+#
243+# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
244+# find one, or @{upstream} otherwise.  Once you have set
245+# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
246+# setting the bash.showUpstream config variable.
247+
248+# __gitdir accepts 0 or 1 arguments (i.e., location)
249+# returns location of .git repo
250+__gitdir ()
251+{
252+	# Note: this function is duplicated in git-completion.bash
253+	# When updating it, make sure you update the other one to match.
254+	if [ -z "${1-}" ]; then
255+		if [ -n "${__git_dir-}" ]; then
256+			echo "$__git_dir"
257+		elif [ -n "${GIT_DIR-}" ]; then
258+			test -d "${GIT_DIR-}" || return 1
259+			echo "$GIT_DIR"
260+		elif [ -d .git ]; then
261+			echo .git
262+		else
263+			git rev-parse --git-dir 2>/dev/null
264+		fi
265+	elif [ -d "$1/.git" ]; then
266+		echo "$1/.git"
267+	else
268+		echo "$1"
269+	fi
270+}
271+
272+# stores the divergence from upstream in $p
273+# used by GIT_PS1_SHOWUPSTREAM
274+__git_ps1_show_upstream ()
275+{
276+	local key value
277+	local svn_remote svn_url_pattern count n
278+	local upstream=git legacy="" verbose=""
279+
280+	svn_remote=()
281+	# get some config options from git-config
282+	local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
283+	while read -r key value; do
284+		case "$key" in
285+		bash.showupstream)
286+			GIT_PS1_SHOWUPSTREAM="$value"
287+			if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
288+				p=""
289+				return
290+			fi
291+			;;
292+		svn-remote.*.url)
293+			svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
294+			svn_url_pattern+="\\|$value"
295diff --git a/plugins/gitfast/gitfast.plugin.zsh b/plugins/gitfast/gitfast.plugin.zsh
296new file mode 100644
297index 0000000000000000000000000000000000000000..7e50cf721cb33e5f090379cb43b2c53950a17902
298--- /dev/null
299+++ b/plugins/gitfast/gitfast.plugin.zsh
300@@ -0,0 +1,7 @@
301+dir=$(dirname $0)
302+source $dir/../git/git.plugin.zsh
303+source $dir/git-prompt.sh
304+
305+function git_prompt_info() {
306+  __git_ps1 "${ZSH_THEME_GIT_PROMPT_PREFIX//\%/%%}%s${ZSH_THEME_GIT_PROMPT_SUFFIX//\%/%%}"
307+}