zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Roland Eggner <edvz2@systemanalysen.net>,
	zsh workers <zsh-workers@zsh.org>
Subject: Re: Parameter + prompt expansion %D{%T.%.} parser issue
Date: Mon, 18 Jul 2016 20:48:15 -0700	[thread overview]
Message-ID: <160718204815.ZM6266@torch.brasslantern.com> (raw)
In-Reply-To: <CAHYJk3QPHyH30z+iZ8=o9WPviA4F_=sFMFwEeVdBq65GkWEddw@mail.gmail.com>

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.%.} %~"}"


      reply	other threads:[~2016-07-19  3:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-18 20:31 Roland Eggner
2016-07-19  0:21 ` Mikael Magnusson
2016-07-19  3:48   ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160718204815.ZM6266@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=edvz2@systemanalysen.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).