zsh-users
 help / color / mirror / code / Atom feed
* Suppressing "no matches found" Glob Message?
@ 2004-06-27  2:39 Aaron Davies
  2004-06-27 10:42 ` DervishD
  0 siblings, 1 reply; 14+ messages in thread
From: Aaron Davies @ 2004-06-27  2:39 UTC (permalink / raw)
  To: zsh-users

Is there an easy way to temporarily turn off the "no matches found" 
message that a failed glob returns? I'm looking mainly for something 
simple enough to use in an alias--I have an alias called "lspf" which 
is defined as "ls **/*(.)", but I'd like to make it return something 
custom if no such files exist. Redirecting stderr doesn't help, because 
(I assume) the message is generated by zsh, not ls.
-- 
     __                      __
    /  )                    /  )
   /--/ __. .__  ______    /  / __. , __o  _  _
  /  (_(_/|_/ (_(_) / (_  (__/_(_/|_\/ <__</_/_)_


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-27  2:39 Suppressing "no matches found" Glob Message? Aaron Davies
@ 2004-06-27 10:42 ` DervishD
  2004-06-27 22:50   ` Aaron Davies
  2004-06-27 22:52   ` Aaron Davies
  0 siblings, 2 replies; 14+ messages in thread
From: DervishD @ 2004-06-27 10:42 UTC (permalink / raw)
  To: Aaron Davies; +Cc: zsh-users

    Hi Aaron :)

 * Aaron Davies <agd12@columbia.edu> dixit:
> Is there an easy way to temporarily turn off the "no matches found" 
> message that a failed glob returns? I'm looking mainly for something 
> simple enough to use in an alias--I have an alias called "lspf" which 
> is defined as "ls **/*(.)", but I'd like to make it return something 
> custom if no such files exist. Redirecting stderr doesn't help, because 
> (I assume) the message is generated by zsh, not ls.

    Yes, change your pattern to, for example 'ls **/*(.N)'. The 'N'
means 'set option NULL_GLOB' for this pattern. This removes the
error.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-27 10:42 ` DervishD
@ 2004-06-27 22:50   ` Aaron Davies
  2004-06-28  8:53     ` DervishD
  2004-06-27 22:52   ` Aaron Davies
  1 sibling, 1 reply; 14+ messages in thread
From: Aaron Davies @ 2004-06-27 22:50 UTC (permalink / raw)
  To: zsh-users

On Jun 27, 2004, at 6:42 AM, DervishD wrote:

> Aaron Davies <agd12@columbia.edu> dixit:
>
>> Is there an easy way to temporarily turn off the "no matches found"
>> message that a failed glob returns? I'm looking mainly for something
>> simple enough to use in an alias--I have an alias called "lspf" which
>> is defined as "ls **/*(.)", but I'd like to make it return something
>> custom if no such files exist. Redirecting stderr doesn't help, 
>> because
>> (I assume) the message is generated by zsh, not ls.
>
> Yes, change your pattern to, for example 'ls **/*(.N)'. The 'N'
> means 'set option NULL_GLOB' for this pattern. This removes the
> error.

NULL_GLOB seems to remove the pattern entirely, so it no longer finds 
plain files only. I think what I want may be NOMATCH instead, but I 
can't figure out a code to set that. Is there one?
-- 
Aaron Davies
agdavi01@louisville.edu


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-27 10:42 ` DervishD
  2004-06-27 22:50   ` Aaron Davies
@ 2004-06-27 22:52   ` Aaron Davies
  1 sibling, 0 replies; 14+ messages in thread
From: Aaron Davies @ 2004-06-27 22:52 UTC (permalink / raw)
  To: zsh-users

On Jun 27, 2004, at 6:42 AM, DervishD wrote:

> Aaron Davies <agd12@columbia.edu> dixit:
>
>> Is there an easy way to temporarily turn off the "no matches found"
>> message that a failed glob returns? I'm looking mainly for something
>> simple enough to use in an alias--I have an alias called "lspf" which
>> is defined as "ls **/*(.)", but I'd like to make it return something
>> custom if no such files exist. Redirecting stderr doesn't help, 
>> because
>> (I assume) the message is generated by zsh, not ls.
>
> Yes, change your pattern to, for example 'ls **/*(.N)'. The 'N'
> means 'set option NULL_GLOB' for this pattern. This removes the
> error.

NULL_GLOB seems to remove the pattern entirely, so it no longer finds 
plain files only. I think what I want may be NOMATCH instead, but I 
can't figure out a code to set that. Is there one?
-- 
Aaron Davies
agdavi01@louisville.edu


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-27 22:50   ` Aaron Davies
@ 2004-06-28  8:53     ` DervishD
  2004-06-28 22:53       ` Aaron Davies
  2004-06-29 16:12       ` Bart Schaefer
  0 siblings, 2 replies; 14+ messages in thread
From: DervishD @ 2004-06-28  8:53 UTC (permalink / raw)
  To: Aaron Davies; +Cc: zsh-users

    Hi Aaron :)

 * Aaron Davies <agdavi01@louisville.edu> dixit:
> >Yes, change your pattern to, for example 'ls **/*(.N)'. The 'N'
> >means 'set option NULL_GLOB' for this pattern. This removes the
> >error.
> NULL_GLOB seems to remove the pattern entirely, so it no longer finds 
> plain files only.

    NULL_GLOB makes zsh deleting the pattern if no match is found,
but happens that 'ls', without options, prints all files and dirs in
the current directory.

> I think what I want may be NOMATCH instead, but I 
> can't figure out a code to set that. Is there one?

    Don't know, but you don't want NOMATCH set: it *prints* an error
if a match is not found. If you unset it, what you are going to have
is the pattern as-is, so 'ls' will complain saying that '**/*(.)'
doesn't exist.

    In certain sense, what you want is impossible. If you issue the
'ls' command with parameters, it will list those parameters (if they
exist), but if you don't give it params, it will list all files and
dirs. You cannot have a way of 'ls' shutting its mouth up if the
pattern doesn't match anything.

    If you want that behaviour, use 'print' instead of 'ls'.
Something like 'print -l **/*(.N)' will do. If you want all details
for the files you will need a loop or something like that.

    Hope that helps :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-28  8:53     ` DervishD
@ 2004-06-28 22:53       ` Aaron Davies
  2004-06-29  8:52         ` DervishD
  2004-06-29 16:12       ` Bart Schaefer
  1 sibling, 1 reply; 14+ messages in thread
From: Aaron Davies @ 2004-06-28 22:53 UTC (permalink / raw)
  To: zsh-users

On Jun 28, 2004, at 4:53 AM, DervishD wrote:

> Aaron Davies <agdavi01@louisville.edu> dixit:
>
>>> Yes, change your pattern to, for example 'ls **/*(.N)'. The 'N'
>>> means 'set option NULL_GLOB' for this pattern. This removes the
>>> error.
>>
>> NULL_GLOB seems to remove the pattern entirely, so it no longer finds
>> plain files only.
>
> NULL_GLOB makes zsh deleting the pattern if no match is found,
> but happens that 'ls', without options, prints all files and dirs in
> the current directory.
>
>> I think what I want may be NOMATCH instead, but I
>> can't figure out a code to set that. Is there one?
>
> Don't know, but you don't want NOMATCH set: it *prints* an error
> if a match is not found. If you unset it, what you are going to have
> is the pattern as-is, so 'ls' will complain saying that '**/*(.)'
> doesn't exist.

That wouldn't be so bad, actually; I could redirect that error to 
/dev/null. So, does anyone know how to set that option in a pattern?
-- 
Aaron Davies
agdavi01@louisville.edu


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-28 22:53       ` Aaron Davies
@ 2004-06-29  8:52         ` DervishD
  2004-06-29  9:56           ` Lloyd Zusman
  0 siblings, 1 reply; 14+ messages in thread
From: DervishD @ 2004-06-29  8:52 UTC (permalink / raw)
  To: Aaron Davies, t; +Cc: zsh-users

    Hi Aaron :)

 * Aaron Davies <agdavi01@louisville.edu> dixit:
> >Don't know, but you don't want NOMATCH set: it *prints* an error
> >if a match is not found. If you unset it, what you are going to have
> >is the pattern as-is, so 'ls' will complain saying that '**/*(.)'
> >doesn't exist.
> That wouldn't be so bad, actually; I could redirect that error to 
> /dev/null. So, does anyone know how to set that option in a pattern?

    I don't know. I've took a look at the manual and I haven't found
anything about it. Anyway, if you are using such pattern you're bound
to zsh, so, why not using 'print' instead of 'ls'? Using the 'stat'
module of zsh will give you all information 'ls' gives.

    Otherwise, your solution of redirecting the error is good. You
just need a shell function in order to set the NOMATCH option,
something like (I'm writing on the fly, so it's untested):

    function special_ls() {

        emulate -L zsh
        setopt NOMATCH

        ls **/*(.) >& /dev/null

        return 0
    }

    That will do.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-29  8:52         ` DervishD
@ 2004-06-29  9:56           ` Lloyd Zusman
  2004-06-29 10:41             ` DervishD
  0 siblings, 1 reply; 14+ messages in thread
From: Lloyd Zusman @ 2004-06-29  9:56 UTC (permalink / raw)
  To: zsh-users

¡Hola Raúl!


DervishD <raul@pleyades.net> writes:

> [ ... ]
>
>  * Aaron Davies <agdavi01@louisville.edu> dixit:
>> That wouldn't be so bad, actually; I could redirect that error to 
>> /dev/null. So, does anyone know how to set that option in a pattern?
>
>     I don't know. I've took a look at the manual and I haven't found
> anything about it. Anyway, if you are using such pattern you're bound
> to zsh, so, why not using 'print' instead of 'ls'? Using the 'stat'
> module of zsh will give you all information 'ls' gives.
>
>     Otherwise, your solution of redirecting the error is good. You
> just need a shell function in order to set the NOMATCH option,
> something like (I'm writing on the fly, so it's untested):
>
>     function special_ls() {
>
>         emulate -L zsh
>         setopt NOMATCH
>
>         ls **/*(.) >& /dev/null
>
>         return 0
>     }


That will print nothing _except_ a possible error message!

How about this?

    function special_ls() {

        emulate -L zsh
        setopt NOMATCH

        { ls **/*(.) } 2>/dev/null

        return 0
    }


-- 
 Lloyd Zusman
 ljz@asfast.com
 God bless you.


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-29  9:56           ` Lloyd Zusman
@ 2004-06-29 10:41             ` DervishD
  0 siblings, 0 replies; 14+ messages in thread
From: DervishD @ 2004-06-29 10:41 UTC (permalink / raw)
  To: Lloyd Zusman; +Cc: zsh-users

    Hi Lloyd :)

    Has been a long time since our last email :))) I'm happy to hear
from you again :)

 * Lloyd Zusman <ljz@asfast.com> dixit:
> >     function special_ls() {
> >
> >         emulate -L zsh
> >         setopt NOMATCH
> >
> >         ls **/*(.) >& /dev/null
> >
> >         return 0
> >     }
> That will print nothing _except_ a possible error message!

    O:)) Sorry, I used >& instead of the correct 2> I was writing
this in a hurry O:)
 
> How about this?
> 
>     function special_ls() {
> 
>         emulate -L zsh
>         setopt NOMATCH
> 
>         { ls **/*(.) } 2>/dev/null
> 
>         return 0
>     }

    Perfecto ;))

    Best regards, Lloyd :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-28  8:53     ` DervishD
  2004-06-28 22:53       ` Aaron Davies
@ 2004-06-29 16:12       ` Bart Schaefer
  2004-06-29 16:34         ` DervishD
  2004-06-29 23:04         ` Aaron Davies
  1 sibling, 2 replies; 14+ messages in thread
From: Bart Schaefer @ 2004-06-29 16:12 UTC (permalink / raw)
  To: zsh-users

On Mon, 28 Jun 2004, DervishD wrote:

>     In certain sense, what you want is impossible. If you issue the 'ls' 
> command with parameters, it will list those parameters (if they exist), 
> but if you don't give it params, it will list all files and dirs. You 
> cannot have a way of 'ls' shutting its mouth up if the pattern doesn't 
> match anything.

Well, no, but you can have zsh not call "ls" in the first place if the
pattern doesn't match anything.

You're on the right track in a later posting on this thread where you used
a function rather than an alias.  Aliases can't do anything but simple 
text replacements which happen before any of the glob patterns or other
expansions are evaluated.  If you want to base a decision on the result of
an expansion, you must use a function.

In this case, something like

 lspf() {
   files=( **/*(.N) )
   if (( $#files ))
   then
     ls $files
   else 
     print -u2 "Dude, where's my file?"
   fi
 }

Of course, when I try that, I get "argument list too long: ls" but that's 
a different issue.


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-29 16:12       ` Bart Schaefer
@ 2004-06-29 16:34         ` DervishD
  2004-06-29 23:04         ` Aaron Davies
  1 sibling, 0 replies; 14+ messages in thread
From: DervishD @ 2004-06-29 16:34 UTC (permalink / raw)
  To: zsh-users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> >     In certain sense, what you want is impossible. If you issue the 'ls' 
> > command with parameters, it will list those parameters (if they exist), 
> > but if you don't give it params, it will list all files and dirs. You 
> > cannot have a way of 'ls' shutting its mouth up if the pattern doesn't 
> > match anything.
> Well, no, but you can have zsh not call "ls" in the first place if the
> pattern doesn't match anything.

    Of course, but I think is faster to use 'find' or even 'print'
together with the stat module, instead of 'ls' and a monster command
line. That expansion **/*, can lead to a huge command line as you
point at the end of your message.

>  lspf() {
>    files=( **/*(.N) )
>    if (( $#files ))
>    then
>      ls $files
>    else 
>      print -u2 "Dude, where's my file?"
>    fi
>  }

    Nice :))))
 
> Of course, when I try that, I get "argument list too long: ls" but that's 
> a different issue.

    You can use xargs, of course, but then you can use 'find' in the
first place.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-29 16:12       ` Bart Schaefer
  2004-06-29 16:34         ` DervishD
@ 2004-06-29 23:04         ` Aaron Davies
  2004-06-30 10:10           ` Bart Schaefer
  1 sibling, 1 reply; 14+ messages in thread
From: Aaron Davies @ 2004-06-29 23:04 UTC (permalink / raw)
  To: zsh-users

On Jun 29, 2004, at 12:12 PM, Bart Schaefer wrote:

> On Mon, 28 Jun 2004, DervishD wrote:
>
>>     In certain sense, what you want is impossible. If you issue the 
>> 'ls'
>> command with parameters, it will list those parameters (if they 
>> exist),
>> but if you don't give it params, it will list all files and dirs. You
>> cannot have a way of 'ls' shutting its mouth up if the pattern doesn't
>> match anything.
>
> Well, no, but you can have zsh not call "ls" in the first place if the
> pattern doesn't match anything.
>
> You're on the right track in a later posting on this thread where you 
> used
> a function rather than an alias.  Aliases can't do anything but simple
> text replacements which happen before any of the glob patterns or other
> expansions are evaluated.  If you want to base a decision on the 
> result of
> an expansion, you must use a function.
>
> In this case, something like
>
>  lspf() {
>    files=( **/*(.N) )
>    if (( $#files ))
>    then
>      ls $files
>    else
>      print -u2 "Dude, where's my file?"
>    fi
>  }

This works great on one of the boxes I use zsh on (a OS X Panther) box, 
but not on the other (a Jaguar box). On the 10.2 one, I get

zsh: lspf: function definition file not found

when I try to run the function, despite having

fpath=(~/Documents/functions $fpath)
autoload lspf

in .zshrc and the above definition for lspf in 
~/Documents/functions/lspf.sh . What's wrong?

> Of course, when I try that, I get "argument list too long: ls" but 
> that's
> a different issue.


-- 
Aaron Davies
agdavi01@louisville.edu


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-29 23:04         ` Aaron Davies
@ 2004-06-30 10:10           ` Bart Schaefer
  2004-07-01  4:28             ` Aaron Davies
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 2004-06-30 10:10 UTC (permalink / raw)
  To: zsh-users

On Tue, 29 Jun 2004, Aaron Davies wrote:

> This works great on one of the boxes I use zsh on (a OS X Panther) box, 
> but not on the other (a Jaguar box). On the 10.2 one, I get
> 
> zsh: lspf: function definition file not found
> 
> when I try to run the function, despite having
> 
> fpath=(~/Documents/functions $fpath)
> autoload lspf
> 
> in .zshrc and the above definition for lspf in 
> ~/Documents/functions/lspf.sh . What's wrong?

The name of the file is supposed to be exactly the same as the name of the 
function -- that is, get rid of the ".sh" extension, there should be no
extension at all.

I have no clue why this would seem to work anywhere; in the condition in
which you've described it, it should always fail.


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

* Re: Suppressing "no matches found" Glob Message?
  2004-06-30 10:10           ` Bart Schaefer
@ 2004-07-01  4:28             ` Aaron Davies
  0 siblings, 0 replies; 14+ messages in thread
From: Aaron Davies @ 2004-07-01  4:28 UTC (permalink / raw)
  To: zsh-users

On Wednesday, June 30, 2004, at 06:10 AM, Bart Schaefer wrote:

> On Tue, 29 Jun 2004, Aaron Davies wrote:
>
>> This works great on one of the boxes I use zsh on (a OS X Panther) 
>> box,
>> but not on the other (a Jaguar box). On the 10.2 one, I get
>>
>> zsh: lspf: function definition file not found
>>
>> when I try to run the function, despite having
>>
>> fpath=(~/Documents/functions $fpath)
>> autoload lspf
>>
>> in .zshrc and the above definition for lspf in
>> ~/Documents/functions/lspf.sh . What's wrong?
>
> The name of the file is supposed to be exactly the same as the name of 
> the
> function -- that is, get rid of the ".sh" extension, there should be no
> extension at all.

Thanks, that did it!
-- 
     __                      __
    /  )                    /  )
   /--/ __. .__  ______    /  / __. , __o  _  _
  /  (_(_/|_/ (_(_) / (_  (__/_(_/|_\/ <__</_/_)_


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

end of thread, other threads:[~2004-07-01  4:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-27  2:39 Suppressing "no matches found" Glob Message? Aaron Davies
2004-06-27 10:42 ` DervishD
2004-06-27 22:50   ` Aaron Davies
2004-06-28  8:53     ` DervishD
2004-06-28 22:53       ` Aaron Davies
2004-06-29  8:52         ` DervishD
2004-06-29  9:56           ` Lloyd Zusman
2004-06-29 10:41             ` DervishD
2004-06-29 16:12       ` Bart Schaefer
2004-06-29 16:34         ` DervishD
2004-06-29 23:04         ` Aaron Davies
2004-06-30 10:10           ` Bart Schaefer
2004-07-01  4:28             ` Aaron Davies
2004-06-27 22:52   ` Aaron Davies

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