Improve _get_comp_words_by_ref()
Empty $cur when cmd = "|a " (| = cursor position)
This commit is contained in:
parent
fc96a951b7
commit
2f37a38b79
@ -348,31 +348,33 @@ __get_cword_at_cursor_by_ref()
|
|||||||
local cword words=()
|
local cword words=()
|
||||||
__reassemble_comp_words_by_ref "$1" words cword
|
__reassemble_comp_words_by_ref "$1" words cword
|
||||||
|
|
||||||
local i cur2
|
local i cur cur2
|
||||||
local cur="$COMP_LINE"
|
local index=$COMP_POINT
|
||||||
local index="$COMP_POINT"
|
if (( index )); then
|
||||||
for (( i = 0; i <= cword; ++i )); do
|
cur=$COMP_LINE
|
||||||
while [[
|
for (( i = 0; i <= cword; ++i )); do
|
||||||
# Current word fits in $cur?
|
while [[
|
||||||
"${#cur}" -ge ${#words[i]} &&
|
# Current word fits in $cur?
|
||||||
# $cur doesn't match cword?
|
"${#cur}" -ge ${#words[i]} &&
|
||||||
"${cur:0:${#words[i]}}" != "${words[i]}"
|
# $cur doesn't match cword?
|
||||||
]]; do
|
"${cur:0:${#words[i]}}" != "${words[i]}"
|
||||||
# Strip first character
|
]]; do
|
||||||
cur="${cur:1}"
|
# Strip first character
|
||||||
# Decrease cursor position
|
cur="${cur:1}"
|
||||||
((index--))
|
# Decrease cursor position
|
||||||
done
|
((index--))
|
||||||
|
done
|
||||||
|
|
||||||
# Does found word match cword?
|
# Does found word match cword?
|
||||||
if [[ "$i" -lt "$cword" ]]; then
|
if [[ "$i" -lt "$cword" ]]; then
|
||||||
# No, cword lies further;
|
# No, cword lies further;
|
||||||
local old_size="${#cur}"
|
local old_size="${#cur}"
|
||||||
cur="${cur#${words[i]}}"
|
cur="${cur#${words[i]}}"
|
||||||
local new_size="${#cur}"
|
local new_size="${#cur}"
|
||||||
index=$(( index - old_size + new_size ))
|
index=$(( index - old_size + new_size ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $index -lt 0 ]]; then
|
if [[ $index -lt 0 ]]; then
|
||||||
# This happens when completing: "command | arg" (| is where
|
# This happens when completing: "command | arg" (| is where
|
||||||
|
Loading…
x
Reference in New Issue
Block a user