zsh-users
 help / color / mirror / code / Atom feed
* Globbing symlinks-to-${glob_qualifier}
@ 2021-08-18  3:27 Zach Riggle
  2021-08-18  3:57 ` Daniel Shahaf
  0 siblings, 1 reply; 17+ messages in thread
From: Zach Riggle @ 2021-08-18  3:27 UTC (permalink / raw)
  To: Zsh Users

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


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18  3:27 Globbing symlinks-to-${glob_qualifier} Zach Riggle
@ 2021-08-18  3:57 ` Daniel Shahaf
  2021-08-18  4:02   ` Bart Schaefer
  0 siblings, 1 reply; 17+ messages in thread
From: Daniel Shahaf @ 2021-08-18  3:57 UTC (permalink / raw)
  To: Zach Riggle, Zsh Users

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


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18  3:57 ` Daniel Shahaf
@ 2021-08-18  4:02   ` Bart Schaefer
  2021-08-18 13:10     ` Zach Riggle
  0 siblings, 1 reply; 17+ messages in thread
From: Bart Schaefer @ 2021-08-18  4:02 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Zach Riggle, Zsh Users

On Tue, Aug 17, 2021 at 8:58 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
>
> Zach Riggle wrote on Wed, 18 Aug 2021 03:27 +00:00:
> >     $ ls -lad *(@/) # Error
> >     $ ls -lad *(/@) # Error
>
> Not an error; just zero matches.

It does become an error when NOMATCH is set, but not because there's
anything illegal about writing that qualifier.


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18  4:02   ` Bart Schaefer
@ 2021-08-18 13:10     ` Zach Riggle
  2021-08-18 15:24       ` Bart Schaefer
  2021-08-19  2:32       ` Globbing symlinks-to-${glob_qualifier} Zach Riggle
  0 siblings, 2 replies; 17+ messages in thread
From: Zach Riggle @ 2021-08-18 13:10 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Daniel Shahaf, Zsh Users

> That'll be «*(@-/)» and «*(@-*)» respectively.

Thanks for the info (and hello to France!)

Definitely easier to read and reason about than *(#q-.)(@)

> Under the hood, «-» simply flips between testing the results of lstat(2) and stat(2).

Ah, that's useful information!  Love these implementation details.

> Not an error; just zero matches.  That's not the same thing.

You're definitely correct, my mistake in terminology.  I'm lucky that
I got "qualifier" and "modifier" correct (I think!)

> It does become an error when NOMATCH is set

That's neat!

The "error" that I got was just '/bin/ls' complaining that there is no
file named e.g. '*(@/)' since the glob didn't find anything (and I
don't have nullglob or nomatch set).  For me, it often helps to employ
Python to see exactly what's being passed in:

    $ python -c 'import sys; print(sys.argv[1:])' *asdfasdfasdf*
    ['*asdfasdfasdf*']

    $ python -c 'import sys; print(sys.argv[1:])' *(@/)
    ['*(@/)']

    $ python -c 'import sys; print(sys.argv[1:])' *(@-/)
    ['pwndbg', 'pwntools']

Turning on nomatch does indeed throw an error from zsh.

    $ setopt nomatch

    $ python -c 'import sys; print(sys.argv[1:])' *(@/)
    zsh: no matches found: *(@/)

Interestingly, it appears that nullglob takes priority over nomatch.
Yet another "Today I Learned."

    $ setopt nullglob nomatch

    $ python -c 'import sys; print(sys.argv[1:])' *(@/)
    []

Zach Riggle


On Tue, Aug 17, 2021 at 11:03 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> On Tue, Aug 17, 2021 at 8:58 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> >
> > Zach Riggle wrote on Wed, 18 Aug 2021 03:27 +00:00:
> > >     $ ls -lad *(@/) # Error
> > >     $ ls -lad *(/@) # Error
> >
> > Not an error; just zero matches.
>
> It does become an error when NOMATCH is set, but not because there's
> anything illegal about writing that qualifier.


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18 13:10     ` Zach Riggle
@ 2021-08-18 15:24       ` Bart Schaefer
  2021-08-18 16:48         ` Ray Andrews
  2021-08-19  2:32       ` Globbing symlinks-to-${glob_qualifier} Zach Riggle
  1 sibling, 1 reply; 17+ messages in thread
From: Bart Schaefer @ 2021-08-18 15:24 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Zsh Users

On Wed, Aug 18, 2021 at 6:11 AM Zach Riggle <zachriggle@gmail.com> wrote:
>
> Interestingly, it appears that nullglob takes priority over nomatch.
> Yet another "Today I Learned."
>
>     $ setopt nullglob nomatch
>
>     $ python -c 'import sys; print(sys.argv[1:])' *(@/)
>     []

You might be interested in cshnullglob.


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18 15:24       ` Bart Schaefer
@ 2021-08-18 16:48         ` Ray Andrews
  2021-08-18 17:23           ` Bart Schaefer
  0 siblings, 1 reply; 17+ messages in thread
From: Ray Andrews @ 2021-08-18 16:48 UTC (permalink / raw)
  To: zsh-users

On 2021-08-18 8:24 a.m., Bart Schaefer wrote:
>
> You might be interested in cshnullglob.
>
This is a half baked musing as much as a question, but would it not be 
inevitable that some of these glob options

nobareglobqual        off
nocaseglob            off
cshnullglob           off
extendedglob          on
noglob                off
noglobalexport        off
noglobalrcs           off
globassign            off
globcomplete          off
globdots              on
globstarshort         on
globsubst             off
kshglob               off
nullglob              on
numericglobsort       off
shglob                off

... must contradict each other?  Options are always on/off, but wouldn't 
the logic of some of these settings be more of a 'radio button' sort of 
thing, where only one of several options can be active? I don't really 
know but, for example, how can you combine shglob, kshglob, nullglob and 
noglob?  It would appear that they can't coexist.




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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18 16:48         ` Ray Andrews
@ 2021-08-18 17:23           ` Bart Schaefer
  2021-08-18 17:55             ` Ray Andrews
  0 siblings, 1 reply; 17+ messages in thread
From: Bart Schaefer @ 2021-08-18 17:23 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Wed, Aug 18, 2021 at 9:48 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> This is a half baked musing as much as a question, but would it not be
> inevitable that some of these glob options

Note that the ones mentioning "global" are not glob options, and
"globcomplete" is a completion option rather than a globbing one.

> ... must contradict each other?  Options are always on/off, but wouldn't
> the logic of some of these settings be more of a 'radio button' sort of
> thing

Yes, there are a few cases where turning on option X causes option Y
to be ignored.  I think those cases are all properly documented, but
extra eyeballs on that sort of thing are never amiss.

There are two reasons we don't want to resort to having "radio button"
option behavior:
(1) The internals use 0/1 bitflags, and using multi-values would be
both a lot of code changes and use more memory.
(2) If you need to locally change X, it's not necessary to
save/restore any other state of Y that might interact with it.  A
prime example of this is "noglob" which obviously disavows a whole
fleet of other options, many of which are not otherwise mutually
exclusive.


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18 17:23           ` Bart Schaefer
@ 2021-08-18 17:55             ` Ray Andrews
  2021-08-18 22:28               ` Which options are really doing anything (Re: Globbing symlinks-to-${glob_qualifier}) Bart Schaefer
  0 siblings, 1 reply; 17+ messages in thread
From: Ray Andrews @ 2021-08-18 17:55 UTC (permalink / raw)
  To: zsh-users

On 2021-08-18 10:23 a.m., Bart Schaefer wrote:
> (1) The internals use 0/1 bitflags, and using multi-values would be
> both a lot of code changes and use more memory.
Sure, I expect that the functioning of options is now pretty much 
written in stone.  One might contemplate some sort of radio button 
situation but it would just push the binary buttons lower down anyway.
> (2) If you need to locally change X, it's not necessary to
> save/restore any other state of Y that might interact with it.  A
> prime example of this is "noglob" which obviously disavows a whole
> fleet of other options
Yeah, one might temporarily disable various other things with 'noglob' 
which would restore things cleanly once it's cancelled. That makes 
sense.  Still one might wish for some way of seeing what's actually 
active at any given time.  'setopt' shows us 'on' or 'off', but not 
'disabled'.    Dunno, the adept will have no need of such a thing but it 
could be educational.  Many of my functions rely on Sebastian's 'znt' 
code and he resets options left right and center and I take most of it 
on faith, but being able to query the actual, functioning state of the 
options would be informative.



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

* Which options are really doing anything (Re: Globbing symlinks-to-${glob_qualifier})
  2021-08-18 17:55             ` Ray Andrews
@ 2021-08-18 22:28               ` Bart Schaefer
  2021-08-18 23:27                 ` Ray Andrews
  0 siblings, 1 reply; 17+ messages in thread
From: Bart Schaefer @ 2021-08-18 22:28 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Wed, Aug 18, 2021 at 10:56 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Still one might wish for some way of seeing what's actually
> active at any given time.  'setopt' shows us 'on' or 'off', but not
> 'disabled'.

Something like the following ... so far this covers only the
globbing-related options; if somebody wants to fill in as many of the
other 172 options as need this, be my guest:

optset () {
  local o
  local -A optset=("${(kv)options[@]}")
  for o in "${(k)options[@]}"
  do
    case $o in
      (bareglobqual) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (numericglobsort) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (globstarshort) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (globsubst) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (globdots) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (extendedglob) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (dotglob) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (caseglob) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (cshnullglob) [[ -o noglob || -o nullglob ]] && optset[$o]=ignored  ;;
      (nullglob) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (kshglob) [[ -o noglob ]] && optset[$o]=ignored  ;;
      (shglob) [[ -o kshglob ]] && optset[$o]=partial
        [[ -o noglob ]] && optset[$o]=ignored  ;;
      (nomatch) [[ ! -o badpattern ]] && optset[$o]=partial
        [[ -o nullglob || -o cshnullglob ]] && optset[$o]=ignored  ;;
    esac
  done
  print -aC2 "${(kv)optset[@]}"
}

If you can think of a better description than "partial" for how shglob
works with kshglob, or for how nomatch interacts with nobadpattern,
jump in there, too.

Aside:  Although the doc says --
"Some options have alternative names.  These aliases are never used
for output, but can be used just like normal option names when
specifying options to the shell."
-- those alternative names actually do appear in the $options hash,
for example globdots and dotglob above.  That accounts for 11 of the
172.


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

* Re: Which options are really doing anything (Re: Globbing symlinks-to-${glob_qualifier})
  2021-08-18 22:28               ` Which options are really doing anything (Re: Globbing symlinks-to-${glob_qualifier}) Bart Schaefer
@ 2021-08-18 23:27                 ` Ray Andrews
  0 siblings, 0 replies; 17+ messages in thread
From: Ray Andrews @ 2021-08-18 23:27 UTC (permalink / raw)
  To: zsh-users

On 2021-08-18 3:28 p.m., Bart Schaefer wrote:

> That accounts for 11 of the
> 172.
>
Cool.  So it can be done.



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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-18 13:10     ` Zach Riggle
  2021-08-18 15:24       ` Bart Schaefer
@ 2021-08-19  2:32       ` Zach Riggle
  2021-08-19  4:38         ` Lawrence Velázquez
  2021-08-19  4:40         ` Bart Schaefer
  1 sibling, 2 replies; 17+ messages in thread
From: Zach Riggle @ 2021-08-19  2:32 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Daniel Shahaf, Zsh Users

Not sure what etiquette is for forking a thread on mailing lists, but
I didn't want to disturb the other discussion on flags/options.

My original question was: "How can I glob for all symlinks to
{directories,files,executables}" and while I did find my own way to
*an* answer, you guys were very helpful at finding a much *better*
answer.

I have a rather ridiculous follow up (no practical application, just
curious how / if it can be done):

How can I glob for all symlinks-to-symlinks-to-a-directory (etc)?  I
expected symlink-to-symlink might be *(@-@) but despite looking quite
cute and similar to either Kirby or Jigglypuff (I can't decide).
However, it doesn't in fact work and I'm just curious if there's more
voodoo in that box.

Zach Riggle


Zach Riggle


On Wed, Aug 18, 2021 at 8:10 AM Zach Riggle <zachriggle@gmail.com> wrote:
>
> > That'll be «*(@-/)» and «*(@-*)» respectively.
>
> Thanks for the info (and hello to France!)
>
> Definitely easier to read and reason about than *(#q-.)(@)
>
> > Under the hood, «-» simply flips between testing the results of lstat(2) and stat(2).
>
> Ah, that's useful information!  Love these implementation details.
>
> > Not an error; just zero matches.  That's not the same thing.
>
> You're definitely correct, my mistake in terminology.  I'm lucky that
> I got "qualifier" and "modifier" correct (I think!)
>
> > It does become an error when NOMATCH is set
>
> That's neat!
>
> The "error" that I got was just '/bin/ls' complaining that there is no
> file named e.g. '*(@/)' since the glob didn't find anything (and I
> don't have nullglob or nomatch set).  For me, it often helps to employ
> Python to see exactly what's being passed in:
>
>     $ python -c 'import sys; print(sys.argv[1:])' *asdfasdfasdf*
>     ['*asdfasdfasdf*']
>
>     $ python -c 'import sys; print(sys.argv[1:])' *(@/)
>     ['*(@/)']
>
>     $ python -c 'import sys; print(sys.argv[1:])' *(@-/)
>     ['pwndbg', 'pwntools']
>
> Turning on nomatch does indeed throw an error from zsh.
>
>     $ setopt nomatch
>
>     $ python -c 'import sys; print(sys.argv[1:])' *(@/)
>     zsh: no matches found: *(@/)
>
> Interestingly, it appears that nullglob takes priority over nomatch.
> Yet another "Today I Learned."
>
>     $ setopt nullglob nomatch
>
>     $ python -c 'import sys; print(sys.argv[1:])' *(@/)
>     []
>
> Zach Riggle
>
>
> On Tue, Aug 17, 2021 at 11:03 PM Bart Schaefer
> <schaefer@brasslantern.com> wrote:
> >
> > On Tue, Aug 17, 2021 at 8:58 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > >
> > > Zach Riggle wrote on Wed, 18 Aug 2021 03:27 +00:00:
> > > >     $ ls -lad *(@/) # Error
> > > >     $ ls -lad *(/@) # Error
> > >
> > > Not an error; just zero matches.
> >
> > It does become an error when NOMATCH is set, but not because there's
> > anything illegal about writing that qualifier.


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-19  2:32       ` Globbing symlinks-to-${glob_qualifier} Zach Riggle
@ 2021-08-19  4:38         ` Lawrence Velázquez
  2021-08-19 13:23           ` Daniel Shahaf
                             ` (2 more replies)
  2021-08-19  4:40         ` Bart Schaefer
  1 sibling, 3 replies; 17+ messages in thread
From: Lawrence Velázquez @ 2021-08-19  4:38 UTC (permalink / raw)
  To: Zach Riggle; +Cc: zsh-users

On Wed, Aug 18, 2021, at 10:32 PM, Zach Riggle wrote:
> Not sure what etiquette is for forking a thread on mailing lists, but
> I didn't want to disturb the other discussion on flags/options.

There isn't really a problem unless you go off on a tangent and the
"Subject" field becomes totally irrelevant, in which case you should
have changed it.  Email is (ostensibly) an asynchronous medium, so
there's no need to wait until one exchange settles down before going
back to address a previous point, as long as you quote properly to
maintain context.

> How can I glob for all symlinks-to-symlinks-to-a-directory (etc)?  I
> expected symlink-to-symlink might be *(@-@) but despite looking quite
> cute and similar to either Kirby or Jigglypuff (I can't decide).

Hm, I thought of another fictional character...

https://en.wikipedia.org/wiki/Billy_the_Puppet

> However, it doesn't in fact work and I'm just curious if there's more
> voodoo in that box.

The zshexpn(1) man page says this...

       -   toggles between making the qualifiers work on symbolic
           links (the default) and the files they point to

...but it would be more accurate if it said "the files they fully
resolve to".  So *(@-@) doesn't give you symlinks that themselves
point to symlinks, it gives you symlinks that *fully resolve to
symlinks*.  AFAICT this only produces results when the symlink chain
is broken.

    % ln -s /bin a
    % ln -s a b
    % ln -s b c
    % ln -s c d
    % printf '<%s>' *(@-/); echo
    <a><b><c><d>
    % printf '<%s>' *(@-@); echo
    zsh: no matches found: *(@-@)
    % rm a
    % printf '<%s>' *(@-@); echo
    <b><c><d>

I'll leave possible solutions to the more daring (and competent).

-- 
vq


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-19  2:32       ` Globbing symlinks-to-${glob_qualifier} Zach Riggle
  2021-08-19  4:38         ` Lawrence Velázquez
@ 2021-08-19  4:40         ` Bart Schaefer
  1 sibling, 0 replies; 17+ messages in thread
From: Bart Schaefer @ 2021-08-19  4:40 UTC (permalink / raw)
  To: Zach Riggle; +Cc: Daniel Shahaf, Zsh Users

On Wed, Aug 18, 2021 at 7:32 PM Zach Riggle <zachriggle@gmail.com> wrote:
>
> How can I glob for all symlinks-to-symlinks-to-a-directory (etc)?

You can run a function from a glob qualifier by using the "e"
qualifier or its shortcut "+".  So it's possible to do almost anything
you want, it just might be slow.

This one shouldn't be too laggy.

zmodload zsh/stat b:zstat
function _ { # Chosen as a short name
  local -a L
  zstat -A L +link $REPLY && [[ -h $L ]]
}

# Print all symlinks to symlinks
print -r -- *(+_)
# Print symlinks to symlinks to directories
print -r -- *(+_-/)

In the last case (as Lawrence noted in a message that came in while I
was typing this) the "-" is going to run down the entire symlink chain
to find the ultimate target, i.e., you can't tell if there are exactly
two symlinks, just that there are at least two.


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-19  4:38         ` Lawrence Velázquez
@ 2021-08-19 13:23           ` Daniel Shahaf
  2021-08-19 13:25           ` Daniel Shahaf
  2021-08-19 13:54           ` Daniel Shahaf
  2 siblings, 0 replies; 17+ messages in thread
From: Daniel Shahaf @ 2021-08-19 13:23 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: Zach Riggle, zsh-users

Lawrence Velázquez wrote on Thu, Aug 19, 2021 at 00:38:11 -0400:
> ...but it would be more accurate if it said "the files they fully
> resolve to".  So *(@-@) doesn't give you symlinks that themselves
> point to symlinks, it gives you symlinks that *fully resolve to
> symlinks*.  AFAICT this only produces results when the symlink chain
> is broken.
> 

Also when there's a symlink loop:

% ln -s foo foo 
% echo foo(@-@) 
foo


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-19  4:38         ` Lawrence Velázquez
  2021-08-19 13:23           ` Daniel Shahaf
@ 2021-08-19 13:25           ` Daniel Shahaf
  2021-08-19 14:38             ` Ray Andrews
  2021-08-19 13:54           ` Daniel Shahaf
  2 siblings, 1 reply; 17+ messages in thread
From: Daniel Shahaf @ 2021-08-19 13:25 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: Zach Riggle, zsh-users

Lawrence Velázquez wrote on Thu, Aug 19, 2021 at 00:38:11 -0400:
> The zshexpn(1) man page says this...
> 
>        -   toggles between making the qualifiers work on symbolic
>            links (the default) and the files they point to
> 
> ...but it would be more accurate if it said "the files they fully
> resolve to".

+1.  Feel free to make it so :)


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-19  4:38         ` Lawrence Velázquez
  2021-08-19 13:23           ` Daniel Shahaf
  2021-08-19 13:25           ` Daniel Shahaf
@ 2021-08-19 13:54           ` Daniel Shahaf
  2 siblings, 0 replies; 17+ messages in thread
From: Daniel Shahaf @ 2021-08-19 13:54 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: Zach Riggle, zsh-users

Lawrence Velázquez wrote on Thu, Aug 19, 2021 at 00:38:11 -0400:
>     % printf '<%s>' *(@-/); echo
>     <a><b><c><d>

That's also an answer to Zach's upthread point about how to print
a glob's expansion exactly.  This solution is POSIX, but can be
ambiguous if the arguments contain «>» or «<» characters.  Alternatives
include:

    % () { typeset -p argv } 'foo bar' '' 'baz'
    typeset -g -a argv=( 'foo bar' '' baz )
    
    % () { print -raC1 -- "${(q-)@}" } 'foo bar' '' 'baz'
    'foo bar'
    ''
    baz

    % () { print -raC1 -- "${(qqqq)@}" } 'foo bar' '' 'baz'
    $'foo bar'
    $''
    $'baz'

The examples use anonymous functions for self-containedness, but feel
free to copy a function to your dotfiles and name it.

The test values test for word splitting and null elision.


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

* Re: Globbing symlinks-to-${glob_qualifier}
  2021-08-19 13:25           ` Daniel Shahaf
@ 2021-08-19 14:38             ` Ray Andrews
  0 siblings, 0 replies; 17+ messages in thread
From: Ray Andrews @ 2021-08-19 14:38 UTC (permalink / raw)
  To: zsh-users

On 2021-08-19 6:25 a.m., Daniel Shahaf wrote:
> +1. Feel free to make it so :)
Shouldn't the competent be touching up the manual whenever and wherever 
needed?  Now and then we read of this or that minor defect or possible 
improvement but are they enacted?


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

end of thread, other threads:[~2021-08-19 14:39 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18  3:27 Globbing symlinks-to-${glob_qualifier} Zach Riggle
2021-08-18  3:57 ` Daniel Shahaf
2021-08-18  4:02   ` Bart Schaefer
2021-08-18 13:10     ` Zach Riggle
2021-08-18 15:24       ` Bart Schaefer
2021-08-18 16:48         ` Ray Andrews
2021-08-18 17:23           ` Bart Schaefer
2021-08-18 17:55             ` Ray Andrews
2021-08-18 22:28               ` Which options are really doing anything (Re: Globbing symlinks-to-${glob_qualifier}) Bart Schaefer
2021-08-18 23:27                 ` Ray Andrews
2021-08-19  2:32       ` Globbing symlinks-to-${glob_qualifier} Zach Riggle
2021-08-19  4:38         ` Lawrence Velázquez
2021-08-19 13:23           ` Daniel Shahaf
2021-08-19 13:25           ` Daniel Shahaf
2021-08-19 14:38             ` Ray Andrews
2021-08-19 13:54           ` Daniel Shahaf
2021-08-19  4:40         ` Bart Schaefer

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