From: Felipe Contreras Date: Thu, 2 Feb 2012 19:48:08 +0000 (-0800) Subject: completion: simplify __gitcomp and __gitcomp_nl implementations X-Git-Tag: v1.7.9.2~16^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=583e4d579d36894ccdc1f4fb4a6dd24c9274c5f8;p=git.git completion: simplify __gitcomp and __gitcomp_nl implementations These shell functions are written in an unnecessarily verbose way; simplify their "conditionally use $ after checking $# against " 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 Signed-off-by: Junio C Hamano --- diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index ec6eed673..6c8dc8f1a 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -495,11 +495,8 @@ fi # 4: A suffix to be appended to each possible completion word (optional). __gitcomp () { - local cur_="$cur" + local cur_="${3-$cur}" - if [ $# -gt 2 ]; then - cur_="$3" - fi case "$cur_" in --*=) COMPREPLY=() @@ -524,18 +521,8 @@ __gitcomp () # appended. __gitcomp_nl () { - local s=$'\n' IFS=' '$'\t'$'\n' - local cur_="$cur" suffix=" " - - if [ $# -gt 2 ]; then - cur_="$3" - if [ $# -gt 3 ]; then - suffix="$4" - fi - fi - - IFS=$s - COMPREPLY=($(compgen -P "${2-}" -S "$suffix" -W "$1" -- "$cur_")) + local IFS=$'\n' + COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}")) } __git_heads ()