Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 66898d08c842f909d01610ad5dbcfcf4abab53de 1 parent ae7f1d1
@rupa authored
Showing with 10 additions and 8 deletions.
  1. +10 −8 z.sh
View
18 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
Please sign in to comment.
Something went wrong with that request. Please try again.