91cb7955cb30797f6b18111aad61d7e8ba80a46a

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

Message

Merge pull request #1739 from felipec/fc/gitfast

Updates to gifast

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/gitfast/_git b/plugins/gitfast/_git
  2index 45775021fff11011a98b90a6b8ebaa72d3d0cd9f..cf8116d4770c5924eaa647763d2bfae3dc14bacf 100644
  3--- a/plugins/gitfast/_git
  4+++ b/plugins/gitfast/_git
  5@@ -60,6 +60,15 @@ __gitcomp_nl ()
  6 	compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  7 }
  8 
  9+__gitcomp_file ()
 10+{
 11+	emulate -L zsh
 12+
 13+	local IFS=$'\n'
 14+	compset -P '*[=:]'
 15+	compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
 16+}
 17+
 18 _git ()
 19 {
 20 	local _ret=1
 21diff --git a/plugins/gitfast/git-completion.bash b/plugins/gitfast/git-completion.bash
 22index be800e09bdf0656951c415105e0d32ce0b0edf9e..93eba467502282db2697e1cf6c93a6909d35ee5c 100644
 23--- a/plugins/gitfast/git-completion.bash
 24+++ b/plugins/gitfast/git-completion.bash
 25@@ -13,6 +13,7 @@
 26 #    *) .git/remotes file names
 27 #    *) git 'subcommands'
 28 #    *) tree paths within 'ref:path/to/file' expressions
 29+#    *) file paths within current working directory and index
 30 #    *) common --long-options
 31 #
 32 # To use these routines:
 33@@ -23,10 +24,6 @@
 34 #    3) Consider changing your PS1 to also show the current branch,
 35 #       see git-prompt.sh for details.
 36 
 37-if [[ -n ${ZSH_VERSION-} ]]; then
 38-	autoload -U +X bashcompinit && bashcompinit
 39-fi
 40-
 41 case "$COMP_WORDBREAKS" in
 42 *:*) : great ;;
 43 *)   COMP_WORDBREAKS="$COMP_WORDBREAKS:"
 44@@ -169,7 +166,6 @@ __git_reassemble_comp_words_by_ref()
 45 }
 46 
 47 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
 48-if [[ -z ${ZSH_VERSION:+set} ]]; then
 49 _get_comp_words_by_ref ()
 50 {
 51 	local exclude cur_ words_ cword_
 52@@ -197,32 +193,6 @@ _get_comp_words_by_ref ()
 53 		shift
 54 	done
 55 }
 56-else
 57-_get_comp_words_by_ref ()
 58-{
 59-	while [ $# -gt 0 ]; do
 60-		case "$1" in
 61-		cur)
 62-			cur=${COMP_WORDS[COMP_CWORD]}
 63-			;;
 64-		prev)
 65-			prev=${COMP_WORDS[COMP_CWORD-1]}
 66-			;;
 67-		words)
 68-			words=("${COMP_WORDS[@]}")
 69-			;;
 70-		cword)
 71-			cword=$COMP_CWORD
 72-			;;
 73-		-n)
 74-			# assume COMP_WORDBREAKS is already set sanely
 75-			shift
 76-			;;
 77-		esac
 78-		shift
 79-	done
 80-}
 81-fi
 82 fi
 83 
 84 # Generates completion reply with compgen, appending a space to possible
 85@@ -264,6 +234,124 @@ __gitcomp_nl ()
 86 	COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
 87 }
 88 
 89+# Generates completion reply with compgen from newline-separated possible
 90+# completion filenames.
 91+# It accepts 1 to 3 arguments:
 92+# 1: List of possible completion filenames, separated by a single newline.
 93+# 2: A directory prefix to be added to each possible completion filename
 94+#    (optional).
 95+# 3: Generate possible completion matches for this word (optional).
 96+__gitcomp_file ()
 97+{
 98+	local IFS=$'\n'
 99+
100+	# XXX does not work when the directory prefix contains a tilde,
101+	# since tilde expansion is not applied.
102+	# This means that COMPREPLY will be empty and Bash default
103+	# completion will be used.
104+	COMPREPLY=($(compgen -P "${2-}" -W "$1" -- "${3-$cur}"))
105+
106+	# Tell Bash that compspec generates filenames.
107+	compopt -o filenames 2>/dev/null
108+}
109+
110+__git_index_file_list_filter_compat ()
111+{
112+	local path
113+
114+	while read -r path; do
115+		case "$path" in
116+		?*/*) echo "${path%%/*}/" ;;
117+		*) echo "$path" ;;
118+		esac
119+	done
120+}
121+
122+__git_index_file_list_filter_bash ()
123+{
124+	local path
125diff --git a/plugins/gitfast/git-prompt.sh b/plugins/gitfast/git-prompt.sh
126index afd76e86ebe729c2e6693b81a52842017a5aa079..65f8368f1a7c010e2ac3dbad73043ebc2035cee6 100644
127--- a/plugins/gitfast/git-prompt.sh
128+++ b/plugins/gitfast/git-prompt.sh
129@@ -10,9 +10,22 @@
130 #    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
131 #    2) Add the following line to your .bashrc/.zshrc:
132 #        source ~/.git-prompt.sh
133-#    3) Change your PS1 to also show the current branch:
134-#         Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
135-#         ZSH:  PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
136+#    3a) Change your PS1 to call __git_ps1 as
137+#        command-substitution:
138+#        Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
139+#        ZSH:  PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
140+#        the optional argument will be used as format string.
141+#    3b) Alternatively, if you are using bash, __git_ps1 can be
142+#        used for PROMPT_COMMAND with two parameters, <pre> and
143+#        <post>, which are strings you would put in $PS1 before
144+#        and after the status string generated by the git-prompt
145+#        machinery.  e.g.
146+#           PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
147+#        will show username, at-sign, host, colon, cwd, then
148+#        various status string, followed by dollar and SP, as
149+#        your prompt.
150+#        Optionally, you can supply a third argument with a printf
151+#        format string to finetune the output of the branch status
152 #
153 # The argument to __git_ps1 will be displayed only if you are currently
154 # in a git repository.  The %s token will be the name of the current
155@@ -30,7 +43,10 @@
156 #
157 # If you would like to see if there're untracked files, then you can set
158 # GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
159-# files, then a '%' will be shown next to the branch name.
160+# files, then a '%' will be shown next to the branch name.  You can
161+# configure this per-repository with the bash.showUntrackedFiles
162+# variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is
163+# enabled.
164 #
165 # If you would like to see the difference between HEAD and its upstream,
166 # set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates you are behind, ">"
167@@ -49,6 +65,19 @@
168 # find one, or @{upstream} otherwise.  Once you have set
169 # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
170 # setting the bash.showUpstream config variable.
171+#
172+# If you would like to see more information about the identity of
173+# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
174+# to one of these values:
175+#
176+#     contains      relative to newer annotated tag (v1.6.3.2~35)
177+#     branch        relative to newer tag or branch (master~4)
178+#     describe      relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
179+#     default       exactly matching tag
180+#
181+# If you would like a colored hint about the current dirty state, set
182+# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
183+# the colored output of "git status -sb".
184 
185 # __gitdir accepts 0 or 1 arguments (i.e., location)
186 # returns location of .git repo
187@@ -195,11 +224,43 @@ __git_ps1_show_upstream ()
188 
189 
190 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
191-# returns text to add to bash PS1 prompt (includes branch name)
192+# when called from PS1 using command substitution
193+# in this mode it prints text to add to bash PS1 prompt (includes branch name)
194+#
195+# __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc)
196+# in that case it _sets_ PS1. The arguments are parts of a PS1 string.
197+# when two arguments are given, the first is prepended and the second appended
198+# to the state string when assigned to PS1.
199+# The optional third parameter will be used as printf format string to further
200+# customize the output of the git-status string.
201+# In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
202 __git_ps1 ()
203 {
204+	local pcmode=no
205+	local detached=no
206+	local ps1pc_start='\u@\h:\w '
207+	local ps1pc_end='\$ '
208+	local printf_format=' (%s)'
209+
210+	case "$#" in
211+		2|3)	pcmode=yes
212+			ps1pc_start="$1"
213+			ps1pc_end="$2"
214+			printf_format="${3:-$printf_format}"
215+		;;
216+		0|1)	printf_format="${1:-$printf_format}"
217+		;;
218+		*)	return
219+		;;
220+	esac
221+
222 	local g="$(__gitdir)"
223-	if [ -n "$g" ]; then
224+	if [ -z "$g" ]; then
225+		if [ $pcmode = yes ]; then
226+			#In PC mode PS1 always needs to be set
227+			PS1="$ps1pc_start$ps1pc_end"
228+		fi
229diff --git a/plugins/gitfast/gitfast.plugin.zsh b/plugins/gitfast/gitfast.plugin.zsh
230index 7e50cf721cb33e5f090379cb43b2c53950a17902..dba1b13152007b87b0e4774d3fcc291bc9d9381c 100644
231--- a/plugins/gitfast/gitfast.plugin.zsh
232+++ b/plugins/gitfast/gitfast.plugin.zsh
233@@ -3,5 +3,6 @@ source $dir/../git/git.plugin.zsh
234 source $dir/git-prompt.sh
235 
236 function git_prompt_info() {
237-  __git_ps1 "${ZSH_THEME_GIT_PROMPT_PREFIX//\%/%%}%s${ZSH_THEME_GIT_PROMPT_SUFFIX//\%/%%}"
238+  dirty="$(parse_git_dirty)"
239+  __git_ps1 "${ZSH_THEME_GIT_PROMPT_PREFIX//\%/%%}%s${dirty//\%/%%}${ZSH_THEME_GIT_PROMPT_SUFFIX//\%/%%}"
240 }