Reevaluate the prompt expression each time a prompt is displayed in zsh

I'm readjusting my zsh prompt, based upon the dallas motif and also the dstufft motif from oh-my-zsh. I enjoy just how dallas has numerous areas of the prompt had in variables, that makes it a lot easier to recognize what is taking place.

The trouble is, these strings are reviewed as soon as for development. So when I try to make use of something vibrant, such as the ${PWD/#$HOME/~} of dstufft, after that it no more updates dynamically.

Just how can I get the most effective of both globes? I would certainly such as the prompt separated right into subsections that are reviewed each time the prompt obtains created.

7
2022-06-07 14:40:26
Source Share
Answers: 3

Ok,

I simply require to leave my $ indicators. As an example:

${PWD/#$HOME/~}
\${PWD/#\$HOME/~}
1
2022-06-07 15:12:37
Source

In zsh you need to make use of % runs away for this. As an example, as opposed to ${PWD/#$HOME/~} (as your instance), simply make use of %~.

Read zshall(1) and also seek SIMPLE PROMPT ESCAPES (it is also lengthy to price estimate below).

0
2022-06-07 15:12:32
Source

Make certain that the prompt_subst is activated. If essential, add the adhering to line to your ~/.zshrc:

setopt prompt_subst

This informs zsh to review the prompt string each time it is presenting a prompt. After that, see to it you are appointing PS1 (or a few other variable that is made use of by the prompt motif) as wanted:

PS1='${PWD/#$HOME/~}'

The solitary quotes shield the unique personalities such as $ from being reviewed when you set the variable.

15
2022-06-07 15:11:42
Source