0e31bed555bd061ad521f16a8122698a8f7fb427
- Author
- Robby Russell <robby@planetargon.com>
- Committer
- Robby Russell <robby@planetargon.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git
2index cf8116d4770c5924eaa647763d2bfae3dc14bacf..fac5e711ebbbd074366d89848165e0f9dbc36c36 100644
3--- a/plugins/gitfast/_git
4+++ b/plugins/gitfast/_git
5@@ -2,18 +2,19 @@
6
7 # zsh completion wrapper for git
8 #
9-# You need git's bash completion script installed somewhere, by default on the
10-# same directory as this script.
11+# Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
12 #
13-# If your script is on ~/.git-completion.sh instead, you can configure it on
14-# your ~/.zshrc:
15+# You need git's bash completion script installed somewhere, by default it
16+# would be the location bash-completion uses.
17+#
18+# If your script is somewhere else, you can configure it on your ~/.zshrc:
19 #
20 # zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
21 #
22-# The recommended way to install this script is to copy to
23-# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
24+# The recommended way to install this script is to copy to '~/.zsh/_git', and
25+# then add the following to your ~/.zshrc file:
26 #
27-# fpath=(~/.zsh/completion $fpath)
28+# fpath=(~/.zsh $fpath)
29
30 complete ()
31 {
32@@ -21,8 +22,23 @@ complete ()
33 return 0
34 }
35
36+zstyle -T ':completion:*:*:git:*' tag-order && \
37+ zstyle ':completion:*:*:git:*' tag-order 'common-commands'
38+
39 zstyle -s ":completion:*:*:git:*" script script
40-test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
41+if [ -z "$script" ]; then
42+ local -a locations
43+ local e
44+ locations=(
45+ '/etc/bash_completion.d/git' # fedora, old debian
46+ '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
47+ '/usr/share/bash-completion/git' # gentoo
48+ $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
49+ )
50+ for e in $locations; do
51+ test -f $e && script="$e" && break
52+ done
53+fi
54 ZSH_VERSION='' . "$script"
55
56 __gitcomp ()
57@@ -69,18 +85,131 @@ __gitcomp_file ()
58 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
59 }
60
61+__git_zsh_bash_func ()
62+{
63+ emulate -L ksh
64+
65+ local command=$1
66+
67+ local completion_func="_git_${command//-/_}"
68+ declare -f $completion_func >/dev/null && $completion_func && return
69+
70+ local expansion=$(__git_aliased_command "$command")
71+ if [ -n "$expansion" ]; then
72+ completion_func="_git_${expansion//-/_}"
73+ declare -f $completion_func >/dev/null && $completion_func
74+ fi
75+}
76+
77+__git_zsh_cmd_common ()
78+{
79+ local -a list
80+ list=(
81+ add:'add file contents to the index'
82+ bisect:'find by binary search the change that introduced a bug'
83+ branch:'list, create, or delete branches'
84+ checkout:'checkout a branch or paths to the working tree'
85+ clone:'clone a repository into a new directory'
86+ commit:'record changes to the repository'
87+ diff:'show changes between commits, commit and working tree, etc'
88+ fetch:'download objects and refs from another repository'
89+ grep:'print lines matching a pattern'
90+ init:'create an empty Git repository or reinitialize an existing one'
91+ log:'show commit logs'
92+ merge:'join two or more development histories together'
93+ mv:'move or rename a file, a directory, or a symlink'
94+ pull:'fetch from and merge with another repository or a local branch'
95+ push:'update remote refs along with associated objects'
96+ rebase:'forward-port local commits to the updated upstream head'
97+ reset:'reset current HEAD to the specified state'
98+ rm:'remove files from the working tree and from the index'
99+ show:'show various types of objects'
100+ status:'show the working tree status'
101+ tag:'create, list, delete or verify a tag object signed with GPG')
102+ _describe -t common-commands 'common commands' list && _ret=0
103+}
104+
105diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash
106index 93eba467502282db2697e1cf6c93a6909d35ee5c..5da920ecd9ec1b64760db863d266fdc9c47502de 100644
107--- a/plugins/gitfast/git-completion.bash
108+++ b/plugins/gitfast/git-completion.bash
109@@ -33,8 +33,6 @@ esac
110 # returns location of .git repo
111 __gitdir ()
112 {
113- # Note: this function is duplicated in git-prompt.sh
114- # When updating it, make sure you update the other one to match.
115 if [ -z "${1-}" ]; then
116 if [ -n "${__git_dir-}" ]; then
117 echo "$__git_dir"
118@@ -53,19 +51,6 @@ __gitdir ()
119 fi
120 }
121
122-__gitcomp_1 ()
123-{
124- local c IFS=$' \t\n'
125- for c in $1; do
126- c="$c$2"
127- case $c in
128- --*=*|*.) ;;
129- *) c="$c " ;;
130- esac
131- printf '%s\n' "$c"
132- done
133-}
134-
135 # The following function is based on code from:
136 #
137 # bash_completion - programmable completion functions for bash 3.2+
138@@ -195,8 +180,18 @@ _get_comp_words_by_ref ()
139 }
140 fi
141
142-# Generates completion reply with compgen, appending a space to possible
143-# completion words, if necessary.
144+__gitcompadd ()
145+{
146+ local i=0
147+ for x in $1; do
148+ if [[ "$x" == "$3"* ]]; then
149+ COMPREPLY[i++]="$2$x$4"
150+ fi
151+ done
152+}
153+
154+# Generates completion reply, appending a space to possible completion words,
155+# if necessary.
156 # It accepts 1 to 4 arguments:
157 # 1: List of possible completion words.
158 # 2: A prefix to be added to each possible completion word (optional).
159@@ -208,19 +203,25 @@ __gitcomp ()
160
161 case "$cur_" in
162 --*=)
163- COMPREPLY=()
164 ;;
165 *)
166- local IFS=$'\n'
167- COMPREPLY=($(compgen -P "${2-}" \
168- -W "$(__gitcomp_1 "${1-}" "${4-}")" \
169- -- "$cur_"))
170+ local c i=0 IFS=$' \t\n'
171+ for c in $1; do
172+ c="$c${4-}"
173+ if [[ $c == "$cur_"* ]]; then
174+ case $c in
175+ --*=*|*.) ;;
176+ *) c="$c " ;;
177+ esac
178+ COMPREPLY[i++]="${2-}$c"
179+ fi
180+ done
181 ;;
182 esac
183 }
184
185-# Generates completion reply with compgen from newline-separated possible
186-# completion words by appending a space to all of them.
187+# Generates completion reply from newline-separated possible completion words
188+# by appending a space to all of them.
189 # It accepts 1 to 4 arguments:
190 # 1: List of possible completion words, separated by a single newline.
191 # 2: A prefix to be added to each possible completion word (optional).
192@@ -231,7 +232,7 @@ __gitcomp ()
193 __gitcomp_nl ()
194 {
195 local IFS=$'\n'
196- COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
197+ __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
198 }
199
200 # Generates completion reply with compgen from newline-separated possible
201@@ -249,106 +250,50 @@ __gitcomp_file ()
202 # since tilde expansion is not applied.
203 # This means that COMPREPLY will be empty and Bash default
204 # completion will be used.
205- COMPREPLY=($(compgen -P "${2-}" -W "$1" -- "${3-$cur}"))
206-
207- # Tell Bash that compspec generates filenames.
208- compopt -o filenames 2>/dev/null
209diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
210index 65f8368f1a7c010e2ac3dbad73043ebc2035cee6..a81ef5a482d48b114a81e242109e2f0dec0839ed 100644
211--- a/plugins/gitfast/git-prompt.sh
212+++ b/plugins/gitfast/git-prompt.sh
213@@ -3,7 +3,7 @@
214 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
215 # Distributed under the GNU General Public License, version 2.0.
216 #
217-# This script allows you to see the current branch in your prompt.
218+# This script allows you to see repository status in your prompt.
219 #
220 # To enable:
221 #
222@@ -13,23 +13,27 @@
223 # 3a) Change your PS1 to call __git_ps1 as
224 # command-substitution:
225 # Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
226-# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
227+# ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
228 # the optional argument will be used as format string.
229-# 3b) Alternatively, if you are using bash, __git_ps1 can be
230-# used for PROMPT_COMMAND with two parameters, <pre> and
231-# <post>, which are strings you would put in $PS1 before
232-# and after the status string generated by the git-prompt
233-# machinery. e.g.
234-# PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
235-# will show username, at-sign, host, colon, cwd, then
236-# various status string, followed by dollar and SP, as
237-# your prompt.
238+# 3b) Alternatively, for a slightly faster prompt, __git_ps1 can
239+# be used for PROMPT_COMMAND in Bash or for precmd() in Zsh
240+# with two parameters, <pre> and <post>, which are strings
241+# you would put in $PS1 before and after the status string
242+# generated by the git-prompt machinery. e.g.
243+# Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
244+# will show username, at-sign, host, colon, cwd, then
245+# various status string, followed by dollar and SP, as
246+# your prompt.
247+# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
248+# will show username, pipe, then various status string,
249+# followed by colon, cwd, dollar and SP, as your prompt.
250 # Optionally, you can supply a third argument with a printf
251 # format string to finetune the output of the branch status
252 #
253-# The argument to __git_ps1 will be displayed only if you are currently
254-# in a git repository. The %s token will be the name of the current
255-# branch.
256+# The repository status will be displayed only if you are currently in a
257+# git repository. The %s token is the placeholder for the shown status.
258+#
259+# The prompt status always includes the current branch name.
260 #
261 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
262 # unstaged (*) and staged (+) changes will be shown next to the branch
263@@ -77,31 +81,8 @@
264 #
265 # If you would like a colored hint about the current dirty state, set
266 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
267-# the colored output of "git status -sb".
268-
269-# __gitdir accepts 0 or 1 arguments (i.e., location)
270-# returns location of .git repo
271-__gitdir ()
272-{
273- # Note: this function is duplicated in git-completion.bash
274- # When updating it, make sure you update the other one to match.
275- if [ -z "${1-}" ]; then
276- if [ -n "${__git_dir-}" ]; then
277- echo "$__git_dir"
278- elif [ -n "${GIT_DIR-}" ]; then
279- test -d "${GIT_DIR-}" || return 1
280- echo "$GIT_DIR"
281- elif [ -d .git ]; then
282- echo .git
283- else
284- git rev-parse --git-dir 2>/dev/null
285- fi
286- elif [ -d "$1/.git" ]; then
287- echo "$1/.git"
288- else
289- echo "$1"
290- fi
291-}
292+# the colored output of "git status -sb" and are available only when
293+# using __git_ps1 for PROMPT_COMMAND or precmd.
294
295 # stores the divergence from upstream in $p
296 # used by GIT_PS1_SHOWUPSTREAM
297@@ -124,7 +105,7 @@ __git_ps1_show_upstream ()
298 fi
299 ;;
300 svn-remote.*.url)
301- svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value"
302+ svn_remote[$((${#svn_remote[@]} + 1))]="$value"
303 svn_url_pattern+="\\|$value"
304 upstream=svn+git # default upstream is SVN if available, else git
305 ;;
306@@ -146,10 +127,11 @@ __git_ps1_show_upstream ()
307 svn*)
308 # get the upstream from the "git-svn-id: ..." in a commit message
309 # (git-svn uses essentially the same procedure internally)
310- local svn_upstream=($(git log --first-parent -1 \
311+ local -a svn_upstream
312+ svn_upstream=($(git log --first-parent -1 \