Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Suppressing "no matches found" Glob Message?



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.



Messages sorted by: Reverse Date, Date, Thread, Author