1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-02-24 11:51:19 +01:00

Check for parameter expansions before tilde-expansions (fixes bugs reported

in zsh-workers/13971).
This commit is contained in:
Bart Schaefer 2001-04-13 16:31:39 +00:00
parent 02e0363afa
commit 1bae764d5a

View file

@ -190,7 +190,23 @@ eorig="$orig"
# Now let's have a closer look at the string to complete.
if [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
if [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
# If there is a parameter expansion in the word from the line, we try
# to complete the beast by expanding the prefix and completing anything
# after the first slash after the parameter expansion.
# This fails for things like `f/$foo/b/<TAB>' where the first `f' is
# meant as a partial path.
linepath="${(M)pre##*\$[^/]##/}"
eval 'realpath=${(e)~linepath}' 2>/dev/null
[[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
pre="${pre#${linepath}}"
i="${#linepath//[^\\/]}"
orig="${orig[1,(in:i:)/][1,-2]}"
donepath=
prepaths=( '' )
elif [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
# It begins with `~', so remember anything before the first slash to be able
# to report it to the completion code. Also get an expanded version of it
# (in `realpath'), so that we can generate the matches. Then remove that
@ -241,22 +257,6 @@ if [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
orig="${orig#*/}"
donepath=
prepaths=( '' )
elif [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
# If there is a parameter expansion in the word from the line, we try
# to complete the beast by expanding the prefix and completing anything
# after the first slash after the parameter expansion.
# This fails for things like `f/$foo/b/<TAB>' where the first `f' is
# meant as a partial path.
linepath="${(M)pre##*\$[^/]##/}"
eval 'realpath=${(e)~linepath}' 2>/dev/null
[[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
pre="${pre#${linepath}}"
i="${#linepath//[^\\/]}"
orig="${orig[1,(in:i:)/][1,-2]}"
donepath=
prepaths=( '' )
else
# If the string does not start with a `~' we don't remove a prefix from the
# string.