zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: Recursive Completition
Date: Sun, 19 Aug 2012 20:44:58 +0100	[thread overview]
Message-ID: <20120819204458.7718bde9@pws-pc.ntlworld.com> (raw)
In-Reply-To: <120818171826.ZM18675@torch.brasslantern.com>

On Sat, 18 Aug 2012 17:18:26 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> } Perfect would be just
> } 
> } ls Kern[tab]
> } 
> } to do that. I am aware of the performance implications -- could this
> } be restricted to the user's home dir only so it doesnt try to read the
> } whole OS when in the root.
> 
> This one would require that you create a new widget or a new completion
> function to insert the implicit leading **/ in the right contexts.  It's
> certainly do-able, but I'm going to leave it as an exercise for someone
> else, this time.

Bizarrely, I think I've got this to work as part of normal file
completion, ish.  No, honestly.  Set the recursive-files style to true
and see if this does the right thing.  No documentation yet.  It only
works if there's no "/" in the word on the command line at the point
completion is tried.

I can't be sure this is the best place to put it in the file completion
calling sequence, but that statement is so obvious as hardly to be worth
mentioning...

I wonder if there's some limit we can apply to stop this going haywire?

Index: Completion/Unix/Type/_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_files,v
retrieving revision 1.13
diff -p -u -r1.13 _files
--- Completion/Unix/Type/_files	19 Mar 2010 16:38:26 -0000	1.13
+++ Completion/Unix/Type/_files	19 Aug 2012 19:40:55 -0000
@@ -1,7 +1,7 @@
 #compdef -redirect-,-default-,-default-
 
 local opts tmp glob pat pats expl tag i def descr end ign ret=1 match tried
-local type sdef ignvars ignvar
+local type sdef ignvars ignvar prepath oprefix
 
 zparseopts -a opts \
     '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
@@ -118,7 +118,16 @@ for def in "$pats[@]"; do
       while _next_label "$tag" expl "$descr"; do
         _comp_ignore=( $_comp_ignore $ign )
         if [[ -n "$end" ]]; then
-          _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0
+          if _path_files -g "$pat" "$opts[@]" "$expl[@]"; then
+	    ret=0
+	  elif [[ $PREFIX$SUFFIX != */* ]] && zstyle -t ":completion:${curcontext}:" recursive-files; then
+	    for prepath in **/*(/); do
+	      oprefix=$PREFIX
+	      PREFIX=$prepath/$PREFIX
+	      _path_files -g "$pat" "$opts[@]" "$expl[@]" && ret=0
+	      PREFIX=$oprefix
+	    done
+	  fi
         else
           _path_files "$expl[@]" -g "$pat" "$opts[@]" && ret=0
         fi

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2012-08-19 19:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-18 21:09 Karoly Negyesi
2012-08-19  0:18 ` Bart Schaefer
2012-08-19 19:44   ` Peter Stephenson [this message]
2012-08-19 21:07     ` Karoly Negyesi
2012-08-20  8:57       ` Peter Stephenson
2012-08-20 15:33         ` Bart Schaefer
2012-08-21 18:27           ` Peter Stephenson
2012-12-04  2:13             ` Karoly Negyesi
2012-08-20  9:43   ` René Neumann
2012-08-21  4:58     ` Bart Schaefer

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=20120819204458.7718bde9@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@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).