Skip to content

Commit

Permalink
completion: add new __gitcompadd helper
Browse files Browse the repository at this point in the history
The idea is to never touch the COMPREPLY variable directly.

This allows other completion systems (i.e. zsh) to override
__gitcompadd, and do something different instead.

Also, this allows further optimizations down the line.

There should be no functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Felipe Contreras authored and Junio C Hamano committed Apr 15, 2013
1 parent 0285118 commit 1ce23aa
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ _get_comp_words_by_ref ()
}
fi

__gitcompadd ()
{
COMPREPLY=($(compgen -W "$1" -P "$2" -S "$4" -- "$3"))
}

# Generates completion reply with compgen, appending a space to possible
# completion words, if necessary.
# It accepts 1 to 4 arguments:
Expand All @@ -211,9 +216,7 @@ __gitcomp ()
;;
*)
local IFS=$'\n'
COMPREPLY=($(compgen -P "${2-}" \
-W "$(__gitcomp_1 "${1-}" "${4-}")" \
-- "$cur_"))
__gitcompadd "$(__gitcomp_1 "${1-}" "${4-}")" "${2-}" "$cur_" ""
;;
esac
}
Expand All @@ -230,7 +233,7 @@ __gitcomp ()
__gitcomp_nl ()
{
local IFS=$'\n'
COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
__gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
}

# Generates completion reply with compgen from newline-separated possible
Expand Down Expand Up @@ -1825,7 +1828,7 @@ _git_config ()
local remote="${prev#remote.}"
remote="${remote%.fetch}"
if [ -z "$cur" ]; then
COMPREPLY=("refs/heads/")
__gitcompadd "refs/heads/" "" "" ""
return
fi
__gitcomp_nl "$(__git_refs_remotes "$remote")"
Expand Down

0 comments on commit 1ce23aa

Please sign in to comment.