@@ -345,21 +345,11 @@ __git_dequote ()
#
# RELEASE: 2.x
-# This function can be used to access a tokenized list of words
-# on the command line:
-#
-# __git_reassemble_comp_words_by_ref '=:'
-# if test "${words_[cword_-1]}" = -w
-# then
-# ...
-# fi
-#
-# The argument should be a collection of characters from the list of
-# word completion separators (COMP_WORDBREAKS) to treat as ordinary
-# characters.
+# This function reorganizes the words on the command line to be processed by
+# the rest of the script.
#
# This is roughly equivalent to going back in time and setting
-# COMP_WORDBREAKS to exclude those characters. The intent is to
+# COMP_WORDBREAKS to exclude '=' and ':'. The intent is to
# make option types like --date=<type> and <rev>:<path> easy to
# recognize by treating each shell word as a single token.
#
@@ -367,60 +357,55 @@ __git_dequote ()
# shared with other completion scripts. By the time the completion
# function gets called, COMP_WORDS has already been populated so local
# changes to COMP_WORDBREAKS have no effect.
-#
-# Output: words_, cword_, cur_.
-
-__git_reassemble_comp_words_by_ref()
-{
- local exclude i j first
- # Which word separators to exclude?
- exclude="${1//[^$COMP_WORDBREAKS]}"
- cword_=$COMP_CWORD
- if [ -z "$exclude" ]; then
- words_=("${COMP_WORDS[@]}")
- return
- fi
- # List of word completion separators has shrunk;
- # re-assemble words to complete.
- for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
- # Append each nonempty word consisting of just
- # word separator characters to the current word.
- first=t
- while
- [ $i -gt 0 ] &&
- [ -n "${COMP_WORDS[$i]}" ] &&
- # word consists of excluded word separators
- [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
- do
- # Attach to the previous token,
- # unless the previous token is the command name.
- if [ $j -ge 2 ] && [ -n "$first" ]; then
- ((j--))
- fi
- first=
- words_[$j]=${words_[j]}${COMP_WORDS[i]}
- if [ $i = $COMP_CWORD ]; then
- cword_=$j
- fi
- if (($i < ${#COMP_WORDS[@]} - 1)); then
- ((i++))
- else
- # Done.
- return
- fi
- done
- words_[$j]=${words_[j]}${COMP_WORDS[i]}
- if [ $i = $COMP_CWORD ]; then
- cword_=$j
- fi
- done
-}
if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
_get_comp_words_by_ref ()
{
local words_ cword_
- __git_reassemble_comp_words_by_ref "=:"
+ local exclude i j first
+
+ # Which word separators to exclude?
+ exclude="${COMP_WORDBREAKS//[^=:]}"
+ cword_=$COMP_CWORD
+ if [ -z "$exclude" ]; then
+ words_=("${COMP_WORDS[@]}")
+ else
+ # List of word completion separators has shrunk;
+ # re-assemble words to complete.
+ for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
+ # Append each nonempty word consisting of just
+ # word separator characters to the current word.
+ first=t
+ while
+ [ $i -gt 0 ] &&
+ [ -n "${COMP_WORDS[$i]}" ] &&
+ # word consists of excluded word separators
+ [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
+ do
+ # Attach to the previous token,
+ # unless the previous token is the command name.
+ if [ $j -ge 2 ] && [ -n "$first" ]; then
+ ((j--))
+ fi
+ first=
+ words_[$j]=${words_[j]}${COMP_WORDS[i]}
+ if [ $i = $COMP_CWORD ]; then
+ cword_=$j
+ fi
+ if (($i < ${#COMP_WORDS[@]} - 1)); then
+ ((i++))
+ else
+ # Done.
+ break 2
+ fi
+ done
+ words_[$j]=${words_[j]}${COMP_WORDS[i]}
+ if [ $i = $COMP_CWORD ]; then
+ cword_=$j
+ fi
+ done
+ fi
+
cword=$cword_
cur=${words_[cword]}
prev=${words_[cword-1]}
We don't need a separate function to do what we already know we want to do. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- contrib/completion/git-completion.bash | 109 +++++++++++-------------- 1 file changed, 47 insertions(+), 62 deletions(-)