From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: PATCH 3/5: _imagemagick: complete all files if image files didn't match
Date: Fri, 14 Aug 2015 10:44:16 +0200 [thread overview]
Message-ID: <25646.1439541856@thecus.kiddle.eu> (raw)
In-Reply-To: <150813132743.ZM28791@torch.brasslantern.com>
Bart wrote:
> As I think I've mentioned elsewhere, file-patterns seems to take
> precedence over list-dirst-first anyway. So I suppose it could be
> interpreted as a shorthand, except for the other-files business.
Yes, it is harmless enough as a shorthand.
> That bit is probably trying to do the trick of merging together glob
> qualifiers, and just gets it wrong. I.e. here:
>
> # add `^-/' after `#q' glob qualifier if not there already
> if [[ "$glob" = (#b)(*\(\#q)(*\)) ]]; then
> [[ $match[2] != \^-/* ]] &&
> glob="${match[1]}^-/,${match[2]}"
> else
> glob="$glob(#q^-/)"
> fi
That bit is also getting it wrong: , in a list of glob qualifiers is an
OR and it wants an AND in this case. Just glob="$glob(#q^-/)" would
have done the job.
(The older attempt at merging qualifiers did want an OR which is harder
to do).
> Does it ever make sense to use _files -g '*(/)' ? Or should -/ always
> be used in that case?
In that exact example, -/ should be used but there's definitely
use-cases for globs matching only some directories. For example, to
select a git repository you might want *(e:[[ -d \$REPLY/.git ]]:)
We don't tend to bother in the functions because the directories get
picked up for the directories tag anyway and there's no way to tell the
selected directories apart from those only there because they might be
part of the path to the final directory. You can't use complist colours
because that works on the basis of the group rather than the tag. If you
use separate groups then you get matches duplicated.
Instead of *(-/) for the directories, we ideally need to negate the glob
specified with -g. The trouble is that it is actually quite hard to get
the opposite of a glob. The opposite of *.ext(ab,cd) is something like
^*.ext *.ext(^a,^b)(^c,^d)
It'd probably be easier to expand the glob in an array and use that
array as a filter. I'd be interested if anyone has any ideas on how to
do this.
The patch below strips the defaults down to a single pattern regardless
of -/ and -g. This makes things more consistent with the use of
a file-patterns style.
Oliver
diff --git a/Completion/Unix/Type/_files b/Completion/Unix/Type/_files
index a8ba9b3..fe0780a 100644
--- a/Completion/Unix/Type/_files
+++ b/Completion/Unix/Type/_files
@@ -33,6 +33,8 @@ if (( $tmp[(I)-g*] )); then
# add `#q' to the beginning of any glob qualifier if not there already
[[ "$glob" = (#b)(*\()([^\|\~]##\)) && $match[2] != \#q* ]] &&
glob="${match[1]}#q${match[2]}"
+elif [[ $type = */* ]]; then
+ glob="*(-/)"
fi
tmp=$opts[(I)-F]
if (( tmp )); then
@@ -51,59 +53,21 @@ else
fi
if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
- [[ "$type" = */* ]] && glob="$glob,*(-/)"
pats=()
for i in ${tmp//\%p/${${glob:-\*}//:/\\:}}; do
if [[ $i = *[^\\]:* ]]; then
- pats=( "$pats[@]" " $i " )
+ pats+=( " $i " )
else
- pats=( "$pats[@]" " ${i}:files " )
+ pats+=( " ${i}:files " )
fi
done
elif zstyle -t ":completion:${curcontext}:" list-dirs-first; then
- if [[ "$type" = *g* ]]; then
-
- # add `^-/' after `#q' glob qualifier if not there already
- if [[ "$glob" = (#b)(*\(\#q)(*\)) ]]; then
- [[ $match[2] != \^-/* ]] &&
- glob="${match[1]}^-/,${match[2]}"
- else
- glob="$glob(#q^-/)"
- fi
-
- pats=( " *(-/):directories:directories ${glob//:/\\:}:globbed-files" )
- elif [[ "$type" = */* ]] then
- pats=( '*(-/):directories ' '*:all-files ' )
- else
- pats=( '*(-/):directories:directories *(^-/):other-files ' )
- fi
+ pats=( " *(-/):directories:directory ${${glob:-*}//:/\\:}(#q^-/):globbed-files" '*:all-files' )
else
- if [[ "$type" = *g* ]]; then
-
# People prefer to have directories shown on first try as default.
# Even if the calling function didn't use -/.
- #
- # if [[ "$type" = */* ]]; then
-
- pats=( " ${glob//:/\\:}:globbed-files *(-/):directories" '*:all-files '
-
- ### We could allow _next_tags to offer only globbed-files or directories
- ### by adding:
- ### " ${glob//:/\\:}:only-globbed-files " ' *(-/):only-directories '
-
- )
-
- # else
- # pats=( " ${glob//:/\\:}:globbed-files "
- # '*(-/):directories ' '*:all-files ' )
- # fi
-
- elif [[ "$type" = */* ]]; then
- pats=( '*(-/):directories ' '*:all-files ' )
- else
- pats=( '*:all-files ' )
- fi
+ pats=( "${${glob:-*}//:/\\:}:globbed-files *(-/):directories" '*:all-files ' )
fi
tried=()
next prev parent reply other threads:[~2015-08-14 8:51 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-12 3:04 PATCH 1/5: _git: various fixes Mikael Magnusson
2015-08-12 3:05 ` PATCH 2/5: _wget: complete headers for --header and add --no-use-server-timestamps Mikael Magnusson
2015-08-12 3:05 ` PATCH 3/5: _imagemagick: complete all files if image files didn't match Mikael Magnusson
2015-08-12 17:20 ` Oliver Kiddle
2015-08-12 18:12 ` Mikael Magnusson
2015-08-12 18:59 ` Bart Schaefer
2015-08-12 19:35 ` Mikael Magnusson
2015-08-12 19:42 ` Bart Schaefer
2015-08-12 20:05 ` Mikael Magnusson
2015-08-12 20:57 ` Bart Schaefer
2015-08-12 21:15 ` Mikael Magnusson
2015-08-12 21:44 ` Bart Schaefer
2015-08-12 22:34 ` Mikael Magnusson
2015-08-12 22:46 ` Bart Schaefer
2015-08-12 23:37 ` Mikael Magnusson
2015-08-13 10:12 ` Oliver Kiddle
2015-08-13 20:27 ` Bart Schaefer
2015-08-14 8:44 ` Oliver Kiddle [this message]
2015-08-14 16:18 ` Mikael Magnusson
2015-08-14 16:24 ` Bart Schaefer
2015-08-14 22:31 ` Mikael Magnusson
2015-08-15 0:05 ` Bart Schaefer
2015-08-15 0:52 ` Mikael Magnusson
2015-08-12 3:05 ` PATCH 4/5: _sort: Fix syntax error Mikael Magnusson
2015-08-12 3:05 ` PATCH 5/5: _strftime: Add completion for zsh/datetime's strftime builtin Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=25646.1439541856@thecus.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).