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 <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Feb 2, 2012 at 11:48 UTC 583e4d579d36894ccdc1f4fb4a6dd24c9274c5f8
1 file changed +3 -16
contrib/completion/git-completion.bash
+3 -16
@@ -495,11 +495,8 @@ fi
495 # 4: A suffix to be appended to each possible completion word (optional).
496 __gitcomp ()
497 {
498 - local cur_="$cur"
498 + local cur_="${3-$cur}"
499
500 - if [ $# -gt 2 ]; then
501 - cur_="$3"
502 - fi
500 case "$cur_" in
501 --*=)
502 COMPREPLY=()
@@ -524,18 +521,8 @@ __gitcomp ()
521 # appended.
522 __gitcomp_nl ()
523 {
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}"))
526 }
527
528 __git_heads ()