Skip to content

Commit

Permalink
Merge branch 'rr/completion-branch-config'
Browse files Browse the repository at this point in the history
Two-level configuration variable names in "branch.*" and "remote.*"
hierarchies whose variables are predominantly three-level where not
completed by hitting a <TAB> in bash and zsh completions.

* rr/completion-branch-config:
  completion: fix remote.pushdefault
  completion: fix branch.autosetup(merge|rebase)
  completion: introduce __gitcomp_nl_append ()
  zsh completion: find matching custom bash completion
  • Loading branch information
gitster committed Jan 10, 2014
2 parents 3b9d69e + c39a2f1 commit 30159e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
24 changes: 20 additions & 4 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,22 @@ _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"
fi
done
}

__gitcompadd ()
{
COMPREPLY=()
__gitcompappend "$@"
}

# Generates completion reply, appending a space to possible completion words,
# if necessary.
# It accepts 1 to 4 arguments:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -1827,6 +1841,7 @@ _git_config ()
branch.*)
local pfx="${cur%.*}." cur_="${cur#*.}"
__gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
__gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_"
return
;;
guitool.*.*)
Expand Down Expand Up @@ -1869,6 +1884,7 @@ _git_config ()
remote.*)
local pfx="${cur%.*}." cur_="${cur#*.}"
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
__gitcomp_nl_append "pushdefault" "$pfx" "$cur_"
return
;;
url.*.*)
Expand Down
10 changes: 9 additions & 1 deletion contrib/completion/git-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ if [ -z "$script" ]; then
local -a locations
local e
locations=(
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
'/etc/bash_completion.d/git' # fedora, old debian
'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
'/usr/share/bash-completion/git' # gentoo
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
)
for e in $locations; do
test -f $e && script="$e" && break
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 30159e5

Please sign in to comment.