From 66898d08c842f909d01610ad5dbcfcf4abab53de Mon Sep 17 00:00:00 2001 From: rupa Date: Fri, 10 Aug 2012 02:29:55 -0400 Subject: [PATCH] metacharacters in directory names * quote metachars in tab completions because bash doesn't, or at least, I can't figure out how to tell it to yet. * tell zsh NOT to quote metachars in tab completions because it does, by default. this is irritating, as i'm sure it's better than me at it. * do the irritating metachar quoting that's been a PITA on a copy of the variable, so we can return the original, because gsub modifies in place. TODO: if we're going to be taking over metacharacter quoting, we ought to do it less halfhazardly --- z.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/z.sh b/z.sh index 48c4ed6..8a6d515 100755 --- a/z.sh +++ b/z.sh @@ -86,7 +86,10 @@ _z() { } else { for( i in fnd ) $1 !~ fnd[i] && $1 = "" } - if( $1 ) print $1 + if( $1 ) { + gsub(/[\(\)\[\]\| ]/, "\\\\&", $1) + print $1 + } } ' 2>/dev/null @@ -140,12 +143,11 @@ _z() { if( matches[i] && (!short || length(i) < length(short)) ) short = i } if( short == "/" ) return - - # escape regex chars in right hand side - gsub(/[\(\)\[\]\|]/, "\\\\&", short) - - # shortest match must be common to each match - for( i in matches ) if( matches[i] && i !~ short ) return + # shortest match must be common to each match. escape special characters in + # a copy when testing, so we can return the original. + clean_short = short + gsub(/[\(\)\[\]\|]/, "\\\\&", clean_short) + for( i in matches ) if( matches[i] && i !~ clean_short ) return return short } BEGIN { split(q, a, " ") } @@ -198,5 +200,5 @@ elif compctl &> /dev/null; then read -l compl reply=(${(f)"$(_z --complete "$compl")"}) } - compctl -U -K _z_zsh_tab_completion _z + compctl -Q -U -K _z_zsh_tab_completion _z fi