How do I prompt expansion of Zsh in the same order as Bash?

Asked 2 years ago, Updated 2 years ago, 96 views

1 Answers

The Zsh document says:

If the PROMPT_SUBST option is set, the prompt string is first subject to parameter expansion, command substitution and arthmic expansion.

Therefore, after these three expansions, prompt expansion appears to occur.

If you want to do prompt expansion first, you can use print-P.

prompt%pwd 
/tmp/prompt
prompt%cat./set_prompt.zsh
set-o PROMPT_SUBST

length()
{
    echo "${#1}"
}

PS1 = '$(length"$(print-P%d)")%d$'
prompt%source./set_prompt.zsh
11/tmp/prompt$ 


2022-09-30 17:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.