Skip to content

Commit 75f4965

Browse files
committed
Merge branch 'fc/zsh-completion'
* fc/zsh-completion: completion: simplify __gitcomp and __gitcomp_nl implementations completion: use ls -1 instead of rolling a loop to do that ourselves completion: work around zsh option propagation bug
2 parents 297638a + 583e4d5 commit 75f4965

File tree

1 file changed

+11
-56
lines changed

1 file changed

+11
-56
lines changed

contrib/completion/git-completion.bash

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,8 @@ fi
495495
# 4: A suffix to be appended to each possible completion word (optional).
496496
__gitcomp ()
497497
{
498-
local cur_="$cur"
498+
local cur_="${3-$cur}"
499499

500-
if [ $# -gt 2 ]; then
501-
cur_="$3"
502-
fi
503500
case "$cur_" in
504501
--*=)
505502
COMPREPLY=()
@@ -524,18 +521,8 @@ __gitcomp ()
524521
# appended.
525522
__gitcomp_nl ()
526523
{
527-
local s=$'\n' IFS=' '$'\t'$'\n'
528-
local cur_="$cur" suffix=" "
529-
530-
if [ $# -gt 2 ]; then
531-
cur_="$3"
532-
if [ $# -gt 3 ]; then
533-
suffix="$4"
534-
fi
535-
fi
536-
537-
IFS=$s
538-
COMPREPLY=($(compgen -P "${2-}" -S "$suffix" -W "$1" -- "$cur_"))
524+
local IFS=$'\n'
525+
COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
539526
}
540527

541528
__git_heads ()
@@ -643,13 +630,8 @@ __git_refs_remotes ()
643630

644631
__git_remotes ()
645632
{
646-
local i ngoff IFS=$'\n' d="$(__gitdir)"
647-
__git_shopt -q nullglob || ngoff=1
648-
__git_shopt -s nullglob
649-
for i in "$d/remotes"/*; do
650-
echo ${i#$d/remotes/}
651-
done
652-
[ "$ngoff" ] && __git_shopt -u nullglob
633+
local i IFS=$'\n' d="$(__gitdir)"
634+
test -d "$d/remotes" && ls -1 "$d/remotes"
653635
for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
654636
i="${i#remote.}"
655637
echo "${i/.url*/}"
@@ -676,7 +658,8 @@ __git_merge_strategies=
676658
# is needed.
677659
__git_compute_merge_strategies ()
678660
{
679-
: ${__git_merge_strategies:=$(__git_list_merge_strategies)}
661+
test -n "$__git_merge_strategies" ||
662+
__git_merge_strategies=$(__git_list_merge_strategies)
680663
}
681664

682665
__git_complete_revlist_file ()
@@ -854,7 +837,8 @@ __git_list_all_commands ()
854837
__git_all_commands=
855838
__git_compute_all_commands ()
856839
{
857-
: ${__git_all_commands:=$(__git_list_all_commands)}
840+
test -n "$__git_all_commands" ||
841+
__git_all_commands=$(__git_list_all_commands)
858842
}
859843

860844
__git_list_porcelain_commands ()
@@ -947,7 +931,8 @@ __git_porcelain_commands=
947931
__git_compute_porcelain_commands ()
948932
{
949933
__git_compute_all_commands
950-
: ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
934+
test -n "$__git_porcelain_commands" ||
935+
__git_porcelain_commands=$(__git_list_porcelain_commands)
951936
}
952937

953938
__git_pretty_aliases ()
@@ -2733,33 +2718,3 @@ if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
27332718
complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
27342719
|| complete -o default -o nospace -F _git git.exe
27352720
fi
2736-
2737-
if [[ -n ${ZSH_VERSION-} ]]; then
2738-
__git_shopt () {
2739-
local option
2740-
if [ $# -ne 2 ]; then
2741-
echo "USAGE: $0 (-q|-s|-u) <option>" >&2
2742-
return 1
2743-
fi
2744-
case "$2" in
2745-
nullglob)
2746-
option="$2"
2747-
;;
2748-
*)
2749-
echo "$0: invalid option: $2" >&2
2750-
return 1
2751-
esac
2752-
case "$1" in
2753-
-q) setopt | grep -q "$option" ;;
2754-
-u) unsetopt "$option" ;;
2755-
-s) setopt "$option" ;;
2756-
*)
2757-
echo "$0: invalid flag: $1" >&2
2758-
return 1
2759-
esac
2760-
}
2761-
else
2762-
__git_shopt () {
2763-
shopt "$@"
2764-
}
2765-
fi

0 commit comments

Comments
 (0)