Reverted _get_cword
`_get_cword' is reverted to before commit f6497298. This fixes unittest: "a b:c| with WORDBREAKS -= : should return b:c" (| = cursor position) notably by restoring passing an argument to _get_cword to omit characters from $COMP_WORDBREAKS. At the end of `get_cword', `echo "$cur"' has been changed to `printf "%s" "$cur"'. This fixes unittest: "a -n| should return -n" (| = cursor position)
This commit is contained in:
parent
e20a4cb06e
commit
e663e1cbc0
@ -246,33 +246,29 @@ dequote()
|
||||
# for things like scp where we want to return host:path and not only path.
|
||||
_get_cword()
|
||||
{
|
||||
if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then
|
||||
printf "%s" "${COMP_WORDS[COMP_CWORD]}"
|
||||
else
|
||||
local i
|
||||
local cur="$COMP_LINE"
|
||||
local index="$COMP_POINT"
|
||||
for (( i = 0; i <= COMP_CWORD; ++i )); do
|
||||
while [[ "${#cur}" -ge ${#COMP_WORDS[i]} ]] && [[ "${cur:0:${#COMP_WORDS[i]}}" != "${COMP_WORDS[i]}" ]]; do
|
||||
cur="${cur:1}"
|
||||
index="$(( index - 1 ))"
|
||||
local LC_CTYPE=C
|
||||
local WORDBREAKS=${COMP_WORDBREAKS}
|
||||
if [ -n $1 ]; then
|
||||
for (( i=0; i<${#1}; ++i )); do
|
||||
local char=${1:$i:1}
|
||||
WORDBREAKS=${WORDBREAKS//$char/}
|
||||
done
|
||||
if [[ "$i" -lt "$COMP_CWORD" ]]; then
|
||||
local old_size="${#cur}"
|
||||
cur="${cur#${COMP_WORDS[i]}}"
|
||||
local new_size="${#cur}"
|
||||
index="$(( index - old_size + new_size ))"
|
||||
fi
|
||||
local cur=${COMP_LINE:0:$COMP_POINT}
|
||||
local tmp="${cur}"
|
||||
local word_start=`expr "$tmp" : '.*['"${WORDBREAKS}"']'`
|
||||
while [ "$word_start" -ge 2 ]; do
|
||||
local char=${cur:$(( $word_start - 2 )):1}
|
||||
if [ "$char" != "\\" ]; then
|
||||
break
|
||||
fi
|
||||
tmp=${COMP_LINE:0:$(( $word_start - 2 ))}
|
||||
word_start=`expr "$tmp" : '.*['"${WORDBREAKS}"']'`
|
||||
done
|
||||
|
||||
if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then
|
||||
# We messed up! At least return the whole word so things
|
||||
# keep working
|
||||
printf "%s" "${COMP_WORDS[COMP_CWORD]}"
|
||||
else
|
||||
printf "%s" "${cur:0:$index}"
|
||||
fi
|
||||
fi
|
||||
cur=${cur:$word_start}
|
||||
printf "%s" "$cur"
|
||||
}
|
||||
|
||||
# This function performs file and directory completion. It's better than
|
||||
|
Loading…
x
Reference in New Issue
Block a user