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

Re: Suppressing "no matches found" Glob Message?



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@xxxxxxxxxxxxxx



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