zsh-workers
 help / color / mirror / code / Atom feed
* Feature request? print -e to eval ?
@ 2017-09-05 13:17 ` Marc Chantreux
  2017-09-05 13:35   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Chantreux @ 2017-09-05 13:17 UTC (permalink / raw)
  To: zsh-workers

hello people,
 
i don't know about you but i often eval something i just printed.
for exemple:

status_as_flag () { eval $( print -P "${1?flag name}=%(?.true.false)" ) }

when it would be nice to write

status_as_flag () { print -eP "${1?flag name}=%(?.true.false)" }

(no more subshell and more readable)

what to you think about the idea ?

regards
-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


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

* Re: Feature request? print -e to eval ?
  2017-09-05 13:17 ` Feature request? print -e to eval ? Marc Chantreux
@ 2017-09-05 13:35   ` Peter Stephenson
  2017-09-07  8:34     ` Marc Chantreux
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2017-09-05 13:35 UTC (permalink / raw)
  To: zsh-workers

On Tue, 5 Sep 2017 13:17:14 +0000
Marc Chantreux <khatar@phear.org> wrote:
> i don't know about you but i often eval something i just printed.
> for exemple:
> 
> status_as_flag () { eval $( print -P "${1?flag name}=%(?.true.false)" ) }
> 
> when it would be nice to write
> 
> status_as_flag () { print -eP "${1?flag name}=%(?.true.false)" }
> 
> (no more subshell and more readable)
> 
> what to you think about the idea ?

Have a look at the (%) flag to ${...}.  For example,

${(%):-'blah blah'}

substitues blah blah expanded as a prompt.  You can assign that and
print it.

In general, assigning a value then printing it and evaluating
it if you need is probably the way to go.

pws


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

* Re: Feature request? print -e to eval ?
  2017-09-05 13:35   ` Peter Stephenson
@ 2017-09-07  8:34     ` Marc Chantreux
  0 siblings, 0 replies; 3+ messages in thread
From: Marc Chantreux @ 2017-09-07  8:34 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

hello,

> Have a look at the (%) flag to ${...}.

\o/ i missed it for so long ! thank you very much Peter.

the only one thing missing to make evalp obsolete is to defer the
interpolation of a variable

	command=(echo '%(?.true.false) $USER' ); ${(%):-$command}

isn't good because $USER in never interpolated (even if setopt promptsubst)
and of course, the "" are bad because it interpols as it sets up
$command.

i really would like to write something like:

	c=( echo 'dear $USER, you did it %(?.fine.wrong)' )
	${(%):-$c}

but again: the (%) tip is a perfect addition to my daily zsh toolkit.
thank you for that.

regards

-- 
Marc Chantreux (eiro on github and freenode)
http://eiro.github.com/
http://eiro.github.com/atom.xml
"Don't believe everything you read on the Internet"
    -- Abraham Lincoln


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

end of thread, other threads:[~2017-09-07  8:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170905132422epcas3p31c37a80ab0b5e5834813335adc4704e7@epcas3p3.samsung.com>
2017-09-05 13:17 ` Feature request? print -e to eval ? Marc Chantreux
2017-09-05 13:35   ` Peter Stephenson
2017-09-07  8:34     ` Marc Chantreux

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