Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: get output of a command in prompt



On Sep 17,  4:14pm, arno. wrote:
}
} Le Saturday 16 September 2006, à 21:01:55PM +0200, Frank a écrit : 
} > zsh% PS1='$(printf "%s: %d" "This is a one" 1)-%% '
} > $(printf ": /home/hawk" "This is a one" 1)-% setopt promptsubst 
} > This is a one: 1-%
} 
} Yes, I've tried things like that, but the problem is that command output 
} will be evaluated once, just when prompt is set up.

Not true.  The quoting is important:  Note where single quotes (') have
been used and where double quotes have.  Compare:

PS1="$(printf '%s: %d' 'This is a one' 1)-%% " ;: This is the wrong way
PS1='$(printf "%s: %d" "This is a one" 1)-%% ' ;: This is the right way

} It will not be evaluated each time prompt is displayed

It will if the quoting is right and the promptsubst option has been set.

Question for zsh-workers:  Why is the prompt string being evaluated more
than once on every zle reset?

torch% PS1='z is $((++z)) %# '
z is $((++z)) % setopt promptsubst
z is 2 % echo I expect three
I expect three
z is 5 % 
z is 8 % echo I guess I should expect eleven
I guess I should expect eleven
z is 11 % 

This could be expensive for command substitutions in the prompt.



Messages sorted by: Reverse Date, Date, Thread, Author