From 1bae764d5a483bf975a967f20086598fe3906b47 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Fri, 13 Apr 2001 16:31:39 +0000 Subject: Check for parameter expansions before tilde-expansions (fixes bugs reported in zsh-workers/13971). --- Completion/Unix/Type/_path_files | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'Completion/Unix/Type/_path_files') diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files index 541a883e8..bc784426c 100644 --- a/Completion/Unix/Type/_path_files +++ b/Completion/Unix/Type/_path_files @@ -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/' 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/' 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. -- cgit 1.4.1