From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10563 invoked by alias); 14 Aug 2015 08:51:06 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36165 Received: (qmail 13114 invoked from network); 14 Aug 2015 08:51:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1439541857; bh=kdI7lsdXacF9IRsgo8dbK9AUgo4klIq4c4M9nvJ/fRU=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=LFN/cUCUJBgdob/uazftspiFtlEI5YrQFdogGPM9U9nbKiYQoOGlSX60KgUk9kwiYL1OsmGDYjTLry+ylm9tKcZOVDbjbQzh/z/skI9gBHWpmxMmRy/8pyoHXet6YfzvlkSY5r4dRnC6u/8cmg+yPfr0vcLj2q7Nl79pXrjs/k98ZN4E/QDayCE8mGztG5SqkgJfMwrPHb1AZ+X6+vzPzraresWMnKB87gm6wRXhDSX8qdDRFtu17TGhqwNPIQpZLX7jVYKAzBKsm5EsXAFmGTyJcx0ZlSaz5JgVDfQiTuuNjZrziu+mIx/qn6CfofyuWDloCQpl0tteE21SV4A2Kw== X-Yahoo-Newman-Id: 282273.66807.bm@smtp122.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: mO6NEEQVM1kIuvKtdPXnFKMcT_87ohYq2g_U0oSSN7Ql5Qs YS9YUA44_7PSulWBlxiXWV0VwHdV7VdNCDNRPAU207LgY9Apfs2Swu1coyES RtC.vvm525uMj0eGRdvgAfSUzvbFrdm0k3nZtISCoUKmmKuMP0jKe7p6PV2Q t8ggh0xacN9sXjXfhNdRBhANe2pJF_dQ2MEfyWu3iVTEA7g1n8takRRx3Ztn xj7d0gvuOsZz2YGpkla101f1c8c7mUhgsCYbF8l3rUJh0c0fZg0Ireb3OIXR dGp_6aszoXRLAQoP9oV9MUO4vFCDdWVlRIhOePuddl8MBLH.jj6uvdgBh09u iF8IcGY3dW9kuJ3Lnuu1XVR4VLVmTjzNEXEhyyunVPSTYsoIm9QRaRzBxbxt nzKBsdbozV6.IruJhIKIdM9oqkZqwSomekEdL.dX2ScTTf.RwrwU07lJ5avc dpa7qEZnEzEK4a6jaS2c9QRKpc1JpL.1tL_KTUdxlfhGaHHTQIYreHDzW7KV V6xocMrBwIK1VPzSOVXoIpK4eB2n9qg-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <150813132743.ZM28791@torch.brasslantern.com> From: Oliver Kiddle References: <1439348703-8268-1-git-send-email-mikachu@gmail.com> <1439348703-8268-3-git-send-email-mikachu@gmail.com> <7518.1439400015@thecus.kiddle.eu> <150812115958.ZM14070@torch.brasslantern.com> <150812135724.ZM14165@torch.brasslantern.com> <150812144433.ZM14263@torch.brasslantern.com> <150812154611.ZM14299@torch.brasslantern.com> <12099.1439460739@thecus.kiddle.eu> <150813132743.ZM28791@torch.brasslantern.com> To: zsh workers Subject: Re: PATCH 3/5: _imagemagick: complete all files if image files didn't match MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25645.1439541856.1@thecus.kiddle.eu> Date: Fri, 14 Aug 2015 10:44:16 +0200 Message-ID: <25646.1439541856@thecus.kiddle.eu> 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=()