Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Globbing symlinks-to-${glob_qualifier}
Zach Riggle wrote on Wed, 18 Aug 2021 03:27 +00:00:
> UPDATE: Managed to figure it out on my own (see update at the end),
> but thought this was still worth posting in case the mail archives get
> indexed by Google.
+1
> My question is whether there's a way to combine the @ with any of the
> other glob qualifiers -- i.e. to glob for symlinks-to-directories or
> symlinks-to-executables.
That'll be «*(@-/)» and «*(@-*)» respectively. The «@» tests the directory entry
for being a symlink, then «-» flips to "testing the directory entry,
unless it's a symlink in which case test what it points to", and «/»
tests the symlink's target for being a directory.
Does not require extendedglob.
Under the hood, «-» simply flips between testing the results of lstat(2)
and stat(2).
> Many of the glob qualifiers are specific, simple, and well-documented
> -- *(*) for executables, *(/) for directories, *(.) for files, and
> *(@) for symlinks.
>
> I tried the obvious combinations, but these didn't work. Not surprising.
>
> $ ls -lad *(/) # Shows all directories
> $ ls -lad *(@/) # Error
> $ ls -lad *(/@) # Error
Not an error; just zero matches. That's not the same thing.
These particular commands will _always_ have zero matches, because no
directory entry can be both a symlink and a directory. (A dirent can be
a symlink _to_ a directory, but a symlink can't _itself_ be a directory.)
> Ultimately, I managed to sort it out and everything works how I want!
Thanks for sharing your steps! It's helpful for our next design discussions :)
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author