Skip to content

Commit

Permalink
completion: simplify __gitcomp and __gitcomp_nl implementations
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Felipe Contreras authored and Junio C Hamano committed Feb 6, 2012
1 parent d79f81a commit 583e4d5
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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=()
Expand All @@ -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 ()
Expand Down

0 comments on commit 583e4d5

Please sign in to comment.