completion: introduce __gitcomp_nl_append ()
There are situations where multiple classes of completions possible. For example branch.<TAB> should try to complete branch.master. branch.autosetupmerge branch.autosetuprebase The first candidate has the suffix ".", and the second/ third candidates have the suffix " ". To facilitate completions of this kind, create a variation of __gitcomp_nl () that appends to the existing list of completion candidates, COMPREPLY. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
d028b8906a
commit
f33c2c0f9e
@ -178,9 +178,9 @@ _get_comp_words_by_ref ()
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__gitcompadd ()
|
__gitcompappend ()
|
||||||
{
|
{
|
||||||
local i=0
|
local i=${#COMPREPLY[@]}
|
||||||
for x in $1; do
|
for x in $1; do
|
||||||
if [[ "$x" == "$3"* ]]; then
|
if [[ "$x" == "$3"* ]]; then
|
||||||
COMPREPLY[i++]="$2$x$4"
|
COMPREPLY[i++]="$2$x$4"
|
||||||
@ -188,6 +188,12 @@ __gitcompadd ()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__gitcompadd ()
|
||||||
|
{
|
||||||
|
COMPREPLY=()
|
||||||
|
__gitcompappend "$@"
|
||||||
|
}
|
||||||
|
|
||||||
# Generates completion reply, appending a space to possible completion words,
|
# Generates completion reply, appending a space to possible completion words,
|
||||||
# if necessary.
|
# if necessary.
|
||||||
# It accepts 1 to 4 arguments:
|
# It accepts 1 to 4 arguments:
|
||||||
@ -218,6 +224,14 @@ __gitcomp ()
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Variation of __gitcomp_nl () that appends to the existing list of
|
||||||
|
# completion candidates, COMPREPLY.
|
||||||
|
__gitcomp_nl_append ()
|
||||||
|
{
|
||||||
|
local IFS=$'\n'
|
||||||
|
__gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
|
||||||
|
}
|
||||||
|
|
||||||
# Generates completion reply from newline-separated possible completion words
|
# Generates completion reply from newline-separated possible completion words
|
||||||
# by appending a space to all of them.
|
# by appending a space to all of them.
|
||||||
# It accepts 1 to 4 arguments:
|
# It accepts 1 to 4 arguments:
|
||||||
@ -229,8 +243,8 @@ __gitcomp ()
|
|||||||
# appended.
|
# appended.
|
||||||
__gitcomp_nl ()
|
__gitcomp_nl ()
|
||||||
{
|
{
|
||||||
local IFS=$'\n'
|
COMPREPLY=()
|
||||||
__gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
|
__gitcomp_nl_append "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generates completion reply with compgen from newline-separated possible
|
# Generates completion reply with compgen from newline-separated possible
|
||||||
|
@ -76,6 +76,14 @@ __gitcomp_nl ()
|
|||||||
compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
|
compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__gitcomp_nl_append ()
|
||||||
|
{
|
||||||
|
emulate -L zsh
|
||||||
|
|
||||||
|
local IFS=$'\n'
|
||||||
|
compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
|
||||||
|
}
|
||||||
|
|
||||||
__gitcomp_file ()
|
__gitcomp_file ()
|
||||||
{
|
{
|
||||||
emulate -L zsh
|
emulate -L zsh
|
||||||
|
Loading…
x
Reference in New Issue
Block a user