From: Ramkumar Ramachandra Date: Sun, 5 Jan 2014 10:18:03 +0000 (+0530) Subject: completion: introduce __gitcomp_nl_append () X-Git-Tag: v1.9-rc0~21^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f33c2c0f9e2258a80e6e406af39e9fa3fd6e430e?hp=--cc completion: introduce __gitcomp_nl_append () There are situations where multiple classes of completions possible. For example branch. should try to complete branch.master. branch.autosetupmerge branch.autosetuprebase The first candidate has the suffix ".", and the second/ third candidates have the suffix " ". To facilitate completions of this kind, create a variation of __gitcomp_nl () that appends to the existing list of completion candidates, COMPREPLY. Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano --- f33c2c0f9e2258a80e6e406af39e9fa3fd6e430e diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 51c2dd4dec..20febffd9d 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -178,9 +178,9 @@ _get_comp_words_by_ref () } fi -__gitcompadd () +__gitcompappend () { - local i=0 + local i=${#COMPREPLY[@]} for x in $1; do if [[ "$x" == "$3"* ]]; then COMPREPLY[i++]="$2$x$4" @@ -188,6 +188,12 @@ __gitcompadd () done } +__gitcompadd () +{ + COMPREPLY=() + __gitcompappend "$@" +} + # Generates completion reply, appending a space to possible completion words, # if necessary. # It accepts 1 to 4 arguments: @@ -218,6 +224,14 @@ __gitcomp () esac } +# Variation of __gitcomp_nl () that appends to the existing list of +# completion candidates, COMPREPLY. +__gitcomp_nl_append () +{ + local IFS=$'\n' + __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" +} + # Generates completion reply from newline-separated possible completion words # by appending a space to all of them. # It accepts 1 to 4 arguments: @@ -229,8 +243,8 @@ __gitcomp () # appended. __gitcomp_nl () { - local IFS=$'\n' - __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }" + COMPREPLY=() + __gitcomp_nl_append "$@" } # Generates completion reply with compgen from newline-separated possible diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 6fca145c06..6b77968572 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -76,6 +76,14 @@ __gitcomp_nl () compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 } +__gitcomp_nl_append () +{ + emulate -L zsh + + local IFS=$'\n' + compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0 +} + __gitcomp_file () { emulate -L zsh