zsh-workers
 help / color / mirror / code / Atom feed
* Parameter + prompt expansion %D{%T.%.} parser issue
@ 2016-07-18 20:31 Roland Eggner
  2016-07-19  0:21 ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Roland Eggner @ 2016-07-18 20:31 UTC (permalink / raw)
  To: zsh-workers

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

emulate -R zsh -c 'print -l ${(%):-%D{%T.%.} %~} "${(%):-%D{%T.%.} %~}" ${(%):-"%D{%T.%.} %~"}'

Expected:
22:03:02.324 ~
22:03:02.324 ~
22:03:02.324 ~

Observed:
22:03:02.324 ~
22:03:02.324 %~}
22:03:02.324 ~


Note the trailing “%~}” in the 2nd line.

ZSH_PATCHLEVEL=zsh-5.2-282-ga22f4ea
uname -m -o
x86_64 GNU/Linux

Usage error?  Bug?  Feature?



-- 
Best regards
Roland Eggner

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 213 bytes --]

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

* Re: Parameter + prompt expansion %D{%T.%.} parser issue
  2016-07-18 20:31 Parameter + prompt expansion %D{%T.%.} parser issue Roland Eggner
@ 2016-07-19  0:21 ` Mikael Magnusson
  2016-07-19  3:48   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2016-07-19  0:21 UTC (permalink / raw)
  To: Roland Eggner, zsh workers

On Mon, Jul 18, 2016 at 10:31 PM, Roland Eggner
<edvz2@systemanalysen.net> wrote:
> emulate -R zsh -c 'print -l ${(%):-%D{%T.%.} %~} "${(%):-%D{%T.%.} %~}" ${(%):-"%D{%T.%.} %~"}'
>
> Expected:
> 22:03:02.324 ~
> 22:03:02.324 ~
> 22:03:02.324 ~
>
> Observed:
> 22:03:02.324 ~
> 22:03:02.324 %~}
> 22:03:02.324 ~
>
>
> Note the trailing “%~}” in the 2nd line.
>
> ZSH_PATCHLEVEL=zsh-5.2-282-ga22f4ea
> uname -m -o
> x86_64 GNU/Linux
>
> Usage error?  Bug?  Feature?

Usage error, but it's kind of hard to understand what's going on there
admittedly. When ${} is unquoted, then the parser "knows" which {}
belong together, but when you have them under double quotes the {} for
the %D are not special in any way, so the terminating } for %D matches
the ${ as well. You need "${(%):-%D{%T.%.\} %~}" (It would also be a
good idea to use -r for print when testing quoting things although in
this case it makes no difference.)

The same thing happens when you use %F{} etc.

-- 
Mikael Magnusson


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

* Re: Parameter + prompt expansion %D{%T.%.} parser issue
  2016-07-19  0:21 ` Mikael Magnusson
@ 2016-07-19  3:48   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2016-07-19  3:48 UTC (permalink / raw)
  To: Roland Eggner, zsh workers

On Jul 19,  2:21am, Mikael Magnusson wrote:
} Subject: Re: Parameter + prompt expansion %D{%T.%.} parser issue
}
} On Mon, Jul 18, 2016 at 10:31 PM, Roland Eggner
} <edvz2@systemanalysen.net> wrote:
} > emulate -R zsh -c 'print -l ${(%):-%D{%T.%.} %~} "${(%):-%D{%T.%.} %~}" ${(%):-"%D{%T.%.} %~"}'
} >
} > Observed:
} > 22:03:02.324 ~
} > 22:03:02.324 %~}
} > 22:03:02.324 ~
} >
} > Usage error?  Bug?  Feature?
} 
} Usage error, but it's kind of hard to understand what's going on there
} admittedly. When ${} is unquoted, then the parser "knows" which {}
} belong together

That's not quite right either.

You can get a better idea what's happening this way:

torch% setopt ignorebraces
torch% print -l ${(%):-%D{%T.%.} %~} "${(%):-%D{%T.%.} %~}" ${(%):-"%D{%T.%.} %~"}
20:33:34.148
%~}
20:33:34.148 %~}
20:33:34.148 ~

In the first (unquoted) case, with the default setopts (no_ignorebraces),
the substring {%T.%.} is parsed like a brace expansion, but then does not
expand because there are no commas.  So it's accidental that it works the
way expected.  With ignorebraces you see parameter expansion end at the
first close brace, leaving %~} to split into another argument to print.

The third form with the part after :- in quotes is really the only right
way, particularly given the space before %~.  Note that with parameter
expansions in all but the most antiquated versions of the shell you can
actually nest double quotes:

    print "${(%):-"%D{%T.%.} %~"}"


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

end of thread, other threads:[~2016-07-19  3:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-18 20:31 Parameter + prompt expansion %D{%T.%.} parser issue Roland Eggner
2016-07-19  0:21 ` Mikael Magnusson
2016-07-19  3:48   ` 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).