zsh-users
 help / color / mirror / code / Atom feed
* How to avoid expansion when completing?
@ 2000-08-03  7:51 Richard Curnow
  2000-08-03  9:19 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Curnow @ 2000-08-03  7:51 UTC (permalink / raw)
  To: Zsh users list

Suppose I have a load of subdirectories, each of which contains a file
called foobar.dat.  I enter 

% wc **/foob<Tab>

hoping to expand this to **/foobar.dat (assuming there's nothing else
starting with 'foob' in any of the subdirectories).  However, I get the
'**' expanded to the first subdirectory name which has a file starting
with 'foob' in it.  (If I keep pressing <Tab> then I cycle round).

I've got the following options set, and I'm running version 3.1.5.

nobeep
completeinword
globcomplete
histignoredups
histverify
ignoreeof
interactive
login
monitor
pushdignoredups
shinstdin
zle

Is there some combination of options I haven't managed to find yet, or
is this just impossible to do?

-- 
Richard Curnow---by day : SuperH Core Architecture at STMicroelectronics
curnowr@bristol.st.com---------www.superh.com-------------www.st.com----
and by night >>---richard.curnow@go.to---http://go.to/richard.curnow/---


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to avoid expansion when completing?
  2000-08-03  7:51 How to avoid expansion when completing? Richard Curnow
@ 2000-08-03  9:19 ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2000-08-03  9:19 UTC (permalink / raw)
  To: Zsh users list, Richard Curnow

> Suppose I have a load of subdirectories, each of which contains a file
> called foobar.dat.  I enter 
> 
> % wc **/foob<Tab>
> 
> hoping to expand this to **/foobar.dat (assuming there's nothing else
> starting with 'foob' in any of the subdirectories).  However, I get the
> '**' expanded to the first subdirectory name which has a file starting
> with 'foob' in it.  (If I keep pressing <Tab> then I cycle round).
> 
> I've got the following options set, and I'm running version 3.1.5.

If you don't mind upgrading, you can do such things with the new bindable
completion widgets in 3.1.9 (maybe 3.1.6, but that's irrelevant if you're
still on 3.1.5).  Assuming the file is unique, you can use
e.g. _most_recent_file (usually bound to ^xm), which would normally put a
`*' on the end and find the most recently modified matching file --- that
ought to be enough for this purpose.

The following function is a trivial modification of that to add all
matching files as possible completions (_glob_expand_and_complete).
Sven probably has a better way of doing it.


#compdef -k complete-word \C-xG

local file tilde etilde
if [[ $PREFIX = \~*/* ]]; then
  tilde=${PREFIX%%/*}
  etilde=${~tilde}
  file=($~PREFIX*$~SUFFIX)
  file=(${file/#$etilde/$tilde})
else
  file=($~PREFIX*$~SUFFIX)
fi
(( $#file )) && compadd -U -i "$IPREFIX" -I "$ISUFFIX" -f -Q $file


-- 
Peter Stephenson <pws@csr.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to avoid expansion when completing?
@ 2000-08-03 10:51 Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 2000-08-03 10:51 UTC (permalink / raw)
  To: zsh-users


Peter Stephenson wrote:

> > Suppose I have a load of subdirectories, each of which contains a file
> > called foobar.dat.  I enter 
> > 
> > % wc **/foob<Tab>
> > 
> > hoping to expand this to **/foobar.dat (assuming there's nothing else
> > starting with 'foob' in any of the subdirectories).  However, I get the
> > '**' expanded to the first subdirectory name which has a file starting
> > with 'foob' in it.  (If I keep pressing <Tab> then I cycle round).
> > 
> > I've got the following options set, and I'm running version 3.1.5.
> 
> If you don't mind upgrading, you can do such things with the new bindable
> completion widgets in 3.1.9 (maybe 3.1.6, but that's irrelevant if you're
> still on 3.1.5).  Assuming the file is unique, you can use
> e.g. _most_recent_file (usually bound to ^xm), which would normally put a
> `*' on the end and find the most recently modified matching file --- that
> ought to be enough for this purpose.
> 
> The following function is a trivial modification of that to add all
> matching files as possible completions (_glob_expand_and_complete).
> Sven probably has a better way of doing it.

Actually, no. I seem to remember Andrej the same question. And I seem
to remember me replying that this could get pretty expensive...

One could write a function that globs and lets one complete the last
pathname component. But it would then probably be easy to find cases
where it should complete the `intersting' part instead, which can be
hard (or even impossible) to identify with complex patterns. Especially
if the possible completions can have different numbers of components.

After thinking about this I gave up thinking about it at all.

It might be possible to add this to _match (together with _path_files;
for those not familiar with the new completion system: these are two
of its functions, _path_files completes filenames and _match offers
something like globcomplete, opnly more powerful). In fact, they
already handle completion of patterns a bit, but they don't try to
restore parts of the completion back to the original pattern, which
would be needed here.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-08-03 10:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-03  7:51 How to avoid expansion when completing? Richard Curnow
2000-08-03  9:19 ` Peter Stephenson
2000-08-03 10:51 Sven Wischnowsky

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