Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
ignore-line style and filenames containing spaces
- X-seq: zsh-workers 32435
- From: "Jun T." <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: ignore-line style and filenames containing spaces
- Date: Thu, 27 Feb 2014 01:32:32 +0900
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
ignore-line style doesn't work properly if an argument contains
spaces in it:
$ zstyle ':completion:*:*:ls:*' ignore-line other
$ mkdir tmp && cd tmp
$ touch 'a b'
$ ls a\ b <tab> # a\ b is offered again
$ rm a\ b <tab> # a\ b is not offered
_rm has its own mechanism for ignoring the filenames already on
the common line. In the patch below, I copied this method into
_description. (In the case of _description what we are completing
may not be filenames, but I hope using the same method as _rm would
cause no problem.)
I also added '|' to the list of the characters to be escaped.
Otherwise, we would get:
$ touch 'x|y'
$ rm x\|y <tab> # x\|y is offered again
Actually, my first try was the following:
line=( ${line//(#m)\\[\[\]()\\*?#<>~\^\|]/\\\\$MATCH} )
This escapes the special characters only if they are already
escaped on the command line. If I use this, then
$ touch f.c f.h
$ rm f.* <tab> # f.c and f.h are not offered
I thought this was better than the current behavior (f.c and f.h
are offered again), but then I have found that a pattern with
glob qualifiers causes a problem:
$ touch fox # fox is not executable
$ rm f*(x) <tab> # fox is NOT offered
so I gave up adding patterns like f.* as is (i.e., without
escaping *) into the array passed to the -F option of _files.
diff --git a/Completion/Base/Core/_description b/Completion/Base/Core/_description
index 3d99327..304c747 100644
--- a/Completion/Base/Core/_description
+++ b/Completion/Base/Core/_description
@@ -47,17 +47,19 @@ if [[ -z "$_comp_no_ignore" ]]; then
zstyle -a ":completion:${curcontext}:$1" ignored-patterns _comp_ignore ||
_comp_ignore=()
- zstyle -s ":completion:${curcontext}:$1" ignore-line hidden &&
+ if zstyle -s ":completion:${curcontext}:$1" ignore-line hidden; then
+ local -a qwords
+ qwords=( ${words//(#m)[\[\]()\\*?#<>~\^\|]/\\$MATCH} )
case "$hidden" in
- true|yes|on|1) _comp_ignore=( "$_comp_ignore[@]" ${(q)"${words[@]}"} );;
- current) _comp_ignore=( "$_comp_ignore[@]" "${(q)words[CURRENT]}" );;
+ true|yes|on|1) _comp_ignore+=( $qwords );;
+ current) _comp_ignore+=( $qwords[CURRENT] );;
current-shown)
[[ "$compstate[old_list]" = *shown* ]] &&
- _comp_ignore=( "$_comp_ignore[@]" "${(q)words[CURRENT]}" );;
- other) _comp_ignore=( "$_comp_ignore[@]"
- "${(@q)words[1,CURRENT-1]}"
- "${(@q)words[CURRENT+1,-1]}" );;
+ _comp_ignore+=( $qwords[CURRENT] );;
+ other) _comp_ignore+=( $qwords[1,CURRENT-1]
+ $qwords[CURRENT+1,-1] );;
esac
+ fi
# Ensure the ignore option is first so we can override it
# for fake-always.
diff --git a/Completion/Unix/Command/_rm b/Completion/Unix/Command/_rm
index 20f44af..1f156c4 100644
--- a/Completion/Unix/Command/_rm
+++ b/Completion/Unix/Command/_rm
@@ -32,13 +32,9 @@ _arguments -C $opts \
case $state in
(file)
- declare -a ignored
- ignored=()
- ((CURRENT > 1)) &&
- ignored+=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
- ((CURRENT < $#line)) &&
- ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
- _files -F ignored && ret=0
+ line[CURRENT]=()
+ line=( ${line//(#m)[\[\]()\\*?#<>~\^\|]/\\$MATCH} )
+ _files -F line && ret=0
;;
esac
Messages sorted by:
Reverse Date,
Date,
Thread,
Author