Skip to content

Commit 583e4d5

Browse files
felipecgitster
authored andcommitted
completion: simplify __gitcomp and __gitcomp_nl implementations
These shell functions are written in an unnecessarily verbose way; simplify their "conditionally use $<number> after checking $# against <number>" logic by using shell's built-in conditional substitution facilities. Also remove the first of the two assignments to IFS in __gitcomp_nl that does not have any effect. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d79f81a commit 583e4d5

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

contrib/completion/git-completion.bash

Lines changed: 3 additions & 16 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 ()

0 commit comments

Comments
 (0)