zsh-workers
 help / color / mirror / code / Atom feed
* The (e) glob qualifier and NO_NOMATCH
@ 2006-06-21 13:49 Bart Schaefer
  2006-06-22 14:12 ` Oliver Kiddle
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2006-06-21 13:49 UTC (permalink / raw)
  To: zsh-workers

It occurs to me that, unlike most of the other glob qualifiers, (e:cmd:)
doesn't necessarily need any existing filename on which to operate.

Consider by comparison _path_files in the completion code, which includes
a hack to force auto-mounting.  Wouldn't it be nice to be able to write a
function "forcemount" that matches a pattern against /etc/hosts or NIS
and mounts all those filesystems?  Then you could use

  for remote in /net/r*(+forcemount); do ...

This currently doesn't work, because once "r*" fails to match anything
in /net, the qualifiers are ignored and the entire string is returned as
the result.  Instead we'd need to call "forcemount" with REPLY set to
the path segment pattern "r*".

Unfortunately it looks like this would need a pretty large reworking of
the globbing code.  The original source string of path segment patterns
isn't kept around anywhere that I immediately see, and NO_NOMATCH is
handled only after the entire scan has completed.  Further, qualifiers
don't seem to have the order-dependence that one might expect:

  print *(e:'reply=(${REPLY}x)':/)

first finds all directories and then appends "x" to their names, rather
than failing entirely because there are no directories having the names
that result after appending an x to an existing name, and

  print *(e:'reply=(${REPLY}x)':e:'reply=(${REPLY}y)':)

does not produce names with "xy" appended, only with "y".

For the time being, I guess this is just food for thought.

-- 


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

* Re: The (e) glob qualifier and NO_NOMATCH
  2006-06-21 13:49 The (e) glob qualifier and NO_NOMATCH Bart Schaefer
@ 2006-06-22 14:12 ` Oliver Kiddle
  2006-06-22 16:51   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2006-06-22 14:12 UTC (permalink / raw)
  To: zsh-workers

Bart wrote:
> Consider by comparison _path_files in the completion code, which includes
> a hack to force auto-mounting.  Wouldn't it be nice to be able to write a
> function "forcemount" that matches a pattern against /etc/hosts or NIS
> and mounts all those filesystems?  Then you could use
> 
>   for remote in /net/r*(+forcemount); do ...
> 
> This currently doesn't work, because once "r*" fails to match anything
> in /net, the qualifiers are ignored and the entire string is returned as
> the result.  Instead we'd need to call "forcemount" with REPLY set to
> the path segment pattern "r*".

The main thing that makes (e) useful is that it runs the function once
for each matched file. forcemount presumably is something that only
needs to run once because the parameter you want to pass is an
unexpanded pattern.

Given that you can do something like:

  for remote in $(forcemount '/net/r*'); do ...

is your point purely that you think the syntax would be nice or are you
thinking in terms of being able to pass the function down through the
completion system so that it is only run if and when _path_files expands
the pattern?

> don't seem to have the order-dependence that one might expect:
> 
>   print *(e:'reply=(${REPLY}x)':/)

In many respects using (e) and modifying $reply makes it more of a
modifier than a qualifier. Perhaps we should have had a :e modifier.

> For the time being, I guess this is just food for thought.

You might also find it interesting to look at the trick I used in
_subversion for tricking globbing into generating files that don't
exist. It does the following:

  _files -g ".svn(/e:_svn_deletedfiles:)"

The use of .svn as the file is largely irrelevant. This works better
than the similar functionality in _cvs because the rest of
_file/_path_files is used). It isn't perfect due to the fact that the
fake files can't have type information associated with them.

Oliver


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

* Re: The (e) glob qualifier and NO_NOMATCH
  2006-06-22 14:12 ` Oliver Kiddle
@ 2006-06-22 16:51   ` Bart Schaefer
  2006-06-23  9:53     ` Oliver Kiddle
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2006-06-22 16:51 UTC (permalink / raw)
  To: zsh-workers

On Jun 22,  4:12pm, Oliver Kiddle wrote:
}
} Given that you can do something like:
} 
}   for remote in $(forcemount '/net/r*'); do ...
} 
} is your point purely that you think the syntax would be nice or are you
} thinking in terms of being able to pass the function down through the
} completion system so that it is only run if and when _path_files expands
} the pattern?

I was just using the completion system as an example of a case where a
nonexistent file is forced to come into existence so it can later be
globbed.  I'm not otherwise thinking in terms of completion at all.

Rather I'm thinking in terms of the "search upwards but stop at the
first file" glob request posted to zsh-users earlier this week.  I
wanted to say

  up() { reply=( (../)#$~REPLY(Odon) ); reply=( $reply[1] ) }

  less adr*(+up)

but "up" is never called because adr* has no matches in the current dir.
 
} In many respects using (e) and modifying $reply makes it more of a
} modifier than a qualifier. Perhaps we should have had a :e modifier.

We already do, it just doesn't mean "eval" ....


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

* Re: The (e) glob qualifier and NO_NOMATCH
  2006-06-22 16:51   ` Bart Schaefer
@ 2006-06-23  9:53     ` Oliver Kiddle
  0 siblings, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2006-06-23  9:53 UTC (permalink / raw)
  To: zsh-workers

Bart wrote:
> Rather I'm thinking in terms of the "search upwards but stop at the
> first file" glob request posted to zsh-users earlier this week.  I
> wanted to say
> 
>   up() { reply=( (../)#$~REPLY(Odon) ); reply=( $reply[1] ) }
> 
>   less adr*(+up)

The closest I can think of that you can get to this is something like
the following:
  up() { print -r "(../)#$1(Odon[1])" }
  alias up='noglob up'

  less ${~$(up adr*)}

That's not much easier to type but it might make more sense to allow
something like $~(up d*) to work than to add a glob qualifier that
alters the pattern.

In the case of the actual searching upwards problem, I've wondered in
the past whether some actual syntax would make sense. I mostly use it
for getting to Ant build.xml files and have considered using bindkey -s
so that something like '.**/' would expand to '(../)#'. A new syntax
could perhaps work a little differently than '(../)#' to avoid needing
(Odon[1]) or ([-1]). Stopping at the first directory that produces a
match is probably enough (searching up from .. to / not down from / to
..).

Oliver


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

end of thread, other threads:[~2006-06-23  9:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-21 13:49 The (e) glob qualifier and NO_NOMATCH Bart Schaefer
2006-06-22 14:12 ` Oliver Kiddle
2006-06-22 16:51   ` Bart Schaefer
2006-06-23  9:53     ` Oliver Kiddle

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