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

Globbing symlinks-to-${glob_qualifier}



Hello guys!

----

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.

----

After the (surprising!) success of my earlier message, I figured this
was worth asking.

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.

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

I also managed to find the bit on the ":" qualifier, after which
everything is treated as a modifier (e.g. "ls -d *(@:A)" passes the
full path of each symlink to "ls").  This should probably be featured
more prominently in the documentation, like the other qualifiers.

I looked at "14.8.7 Glob Qualifiers" and the third paragraph is a bit
hard for me to grok**. For context, I do have the 'extendedglob'
option set.

> If the option EXTENDED_GLOB is set, a different syntax for glob qualifiers is available, namely ‘(#qx)’ where x is any of the same glob qualifiers used in the other format.

I was able to chain things together and get the glob operation to
succeed, but couldn't produce anything of use.

This works to show all things that are (1) files and (2) executable
files -- but not any better than (*) by itself.

    $ ls -lad *(#q*.)

Trying multiple specifiers for symlink-and-directory does not work.

    $ ls -lad *(#q@/)
    ... No such file or directory

Further down, after the documentation, there is discussion of the "-"
qualifier, which can be used (per the example):

> ls -ld -- *(-/)
> lists all directories and symbolic links that point to directories

This is ALMOST what I want -- but I just want the "symbolic links that
point to directories" part.

**UPDATE**: A bit more fiddling around, by combining (#qx) and (-/)
and I ended up with this, which does exactly what I want!

    $ ls -la *(#q-/)(@)

Hurray!  It also works-as-expected with this form for files:

    $ ls -la *(#q-.)(@)

Ultimately, I managed to sort it out and everything works how I want!

Zach Riggle




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