zsh-workers
 help / color / mirror / code / Atom feed
* history expansion - modifiers :h and :t - questions
@ 2023-10-24 19:23 Jim
  2023-10-24 21:56 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Jim @ 2023-10-24 19:23 UTC (permalink / raw)
  To: devs

[-- Attachment #1: Type: text/plain, Size: 1159 bytes --]

Hi everyone,

Maybe this has been discussed before and I haven't found it.  If so, sorry
for the noise.
The man page talks about using :h and I assume by extension :t, in parameter
substitution. If so I was wondering why "digits" doesn't support  a
parameter for the
number(s) following :h or :t? This would be useful in scripting.

print ${DirPath:h$N}
                  ^ does not work


Error message:  "zsh: unrecognized modifier"

I'm not sure if the following is an inconsistency or not.  Man page for :t
states that
0(zero) is treated the same as 1. Should this also apply to :h? This isn't
what
currently happens. Did I miss something in the man page or basics of zsh I
don't
understand?

Thanks for listening.  Again, sorry if this is just noise.

Example of current output for :h and :t

TestPath=/dirlev2/dirlev3/dirlev4

:h  /dirlev2/dirlev3
:h0 /dirlev2/dirlev3                  0 and 1, not the same
:h1 /
:h2 /dirlev2
:h3 /dirlev2/dirlev3
:h4 /dirlev2/dirlev3/dirlev4

:t  dirlev4
:t0 dirlev4                       0 and 1, the same
:t1 dirlev4
:t2 dirlev3/dirlev4
:t3 dirlev2/dirlev3/dirlev4
:t4 /dirlev2/dirlev3/dirlev4

Regards,

Jim Murphy

[-- Attachment #2: Type: text/html, Size: 2137 bytes --]

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

* Re: history expansion - modifiers :h and :t - questions
  2023-10-24 19:23 history expansion - modifiers :h and :t - questions Jim
@ 2023-10-24 21:56 ` Bart Schaefer
  2023-10-24 23:24   ` Jim
  2023-10-26  6:33   ` Stephane Chazelas
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2023-10-24 21:56 UTC (permalink / raw)
  To: linuxtechguy; +Cc: devs

On Tue, Oct 24, 2023 at 12:23 PM Jim <linux.tech.guy@gmail.com> wrote:
>
> print ${DirPath:h$N}
>                   ^ does not work
> Error message:  "zsh: unrecognized modifier"

Yes ... "$" is not a digit.  Parameters are not expanded here.

You can get around this with ${(e):-\${DirPath:h$N}}

> I'm not sure if the following is an inconsistency or not.  Man page for :t states that
> 0(zero) is treated the same as 1. Should this also apply to :h?

The documentation for :t is being a bit too literal.  More accurate
would be to say that 0 is always the same as having no digit at all.
In the case of :t counting from right to left :1 is also the same as
no digit at all, but for :h counting from left to right that's not the
case.


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

* Re: history expansion - modifiers :h and :t - questions
  2023-10-24 21:56 ` Bart Schaefer
@ 2023-10-24 23:24   ` Jim
  2023-10-31 19:21     ` Jim
  2023-10-26  6:33   ` Stephane Chazelas
  1 sibling, 1 reply; 5+ messages in thread
From: Jim @ 2023-10-24 23:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: devs

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

On Tue, Oct 24, 2023 at 4:56 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Tue, Oct 24, 2023 at 12:23 PM Jim <linux.tech.guy@gmail.com> wrote:
>
> You can get around this with ${(e):-\${DirPath:h$N}}
>

I believe I only had one occasion of using the 'e' flag before. Forgot
about it.
Thanks for the reminder.

The documentation for :t is being a bit too literal.  More accurate
> would be to say that 0 is always the same as having no digit at all.
>

Thanks for the info. That makes more sense.

Regards,

Jim

[-- Attachment #2: Type: text/html, Size: 1188 bytes --]

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

* Re: history expansion - modifiers :h and :t - questions
  2023-10-24 21:56 ` Bart Schaefer
  2023-10-24 23:24   ` Jim
@ 2023-10-26  6:33   ` Stephane Chazelas
  1 sibling, 0 replies; 5+ messages in thread
From: Stephane Chazelas @ 2023-10-26  6:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: linuxtechguy, devs

2023-10-24 14:56:39 -0700, Bart Schaefer:
> On Tue, Oct 24, 2023 at 12:23 PM Jim <linux.tech.guy@gmail.com> wrote:
> >
> > print ${DirPath:h$N}
> >                   ^ does not work
> > Error message:  "zsh: unrecognized modifier"
> 
> Yes ... "$" is not a digit.  Parameters are not expanded here.
> 
> You can get around this with ${(e):-\${DirPath:h$N}}
[...]

For existing $DirPath's, see also:

print -r -- $DirPath(N:h$N)

as parameters are expanded in glob qualifiers.

-- 
Stephane


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

* Re: history expansion - modifiers :h and :t - questions
  2023-10-24 23:24   ` Jim
@ 2023-10-31 19:21     ` Jim
  0 siblings, 0 replies; 5+ messages in thread
From: Jim @ 2023-10-31 19:21 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: devs

[-- Attachment #1: Type: text/plain, Size: 1562 bytes --]

On Tue, Oct 24, 2023 at 4:56 PM Bart Schaefer <schaefer@brasslantern.com>
> wrote:
>
> The documentation for :t is being a bit too literal.  More accurate
>> would be to say that 0 is always the same as having no digit at all.
>>
>
Does the following patch make sense?  This applies to both h and t
modifiers.
t already references h as to what actions digits have on the two modifiers
and
the exception t has.

diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 837a85db6..6de49bff6 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -276,7 +276,8 @@ substitution tt($var:h2) is treated as tt(${var:h}2),
not as
 tt(${var:h2}).  No restriction applies to the use of digits in history
 substitution or globbing qualifiers.  If more components are requested
 than are present, the entire path is substituted (so this does not
-trigger a `failed modifier' error in history expansion).
+trigger a `failed modifier' error in history expansion).  0 is treated
+the same as if there were no digits.
 )
 item(tt(l))(
 Convert the words to all lowercase.
@@ -342,7 +343,7 @@ Remove all leading pathname components, leaving the
final component (tail).
 This works like `tt(basename)'.  Any trailing slashes are first removed.
 Decimal digits are handled as described above for (h), but in this
 case that number of trailing components is preserved instead of
-the default 1; 0 is treated the same as 1.
+the default 1.
 )
 item(tt(u))(
 Convert the words to all uppercase.

Just a thought.  Thanks.

Regards,

Jim Murphy

[-- Attachment #2: Type: text/html, Size: 2286 bytes --]

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

end of thread, other threads:[~2023-10-31 19:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24 19:23 history expansion - modifiers :h and :t - questions Jim
2023-10-24 21:56 ` Bart Schaefer
2023-10-24 23:24   ` Jim
2023-10-31 19:21     ` Jim
2023-10-26  6:33   ` Stephane Chazelas

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