zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Recursive Completition
Date: Sat, 18 Aug 2012 17:18:26 -0700	[thread overview]
Message-ID: <120818171826.ZM18675@torch.brasslantern.com> (raw)
In-Reply-To: <CAOfzkkzyFg3xUv+YXGiQwmvyjJqKsAt9-QXD2ptc9_22dvo2RA@mail.gmail.com>

On Aug 18, 11:09pm, Karoly Negyesi wrote:
}
} ls **/Kernel.php[Tab]
} 
} autocompletes to
} 
} core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Kernel.php
} 
} that's really great!

Glad you like it, but you should understand the difference between
_completion_ and _expansion_ before going any further.  What you've
done right there is _expansion_ -- replace a glob pattern with the
thing(s) it matches (expands to).  This happens to be handled as part
of the completion system if you've run "compinit" but it's really not
quite the same thing, because it isn't applying any contextual clues
to the pattern, it's just expanding it.

Note that the default behavior is to try expansion first and complete
only if that fails.
 
} Even better would be if I could have
} 
} ls **/Kern[tab]
} 
} do that (and not just for ls, but everything else).

Here the glob pattern doesn't match (because there's no file named
"Kern" anywhere downstream), so it doesn't expand to anything.  If
you tried

ls **/Kern*[tab]

you'd get something (possibly many somethings).

Fortunately there's a way to move this out of the realm of expansion
and into that of completion; to whit, simply assert that you want
completion to act as if it were using glob patterns:

setopt globcomplete

Now when you try

ls **/Kern[tab]

the completion system behaves as if you'd inserted a * just before [tab],
and offers you the list of matching items as choices.

It's not quite as intutive when encountering a possible branch part way
down the **/ expansion -- you may be offered a set of directories as the
alternatives with no obvious way to choose one of them and then go on
with the same completion.  This gets easier if you force menu-selection
to occur.

} Oh, and maybe display the menu while I am writing a wishlist :)

That's all independently controlled by things like 

setopt automenu
zstyle ':completion:*' menu 'yes=long' 'select=9'

and so on.  There's a bunch of stuff about this toward the end of
section 6.5.2 http://zsh.sourceforge.net/Guide/zshguide06.html#l158
of the user guide.

} 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.


  reply	other threads:[~2012-08-19  0:18 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 [this message]
2012-08-19 19:44   ` Peter Stephenson
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=120818171826.ZM18675@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).