zsh not re-computing my shell prompt

后端 未结 2 376
情话喂你
情话喂你 2021-01-17 11:21

This might be a bit fringe, but I recently moved to zsh and am having a problem customizing my shell prompt.

Part of my .zshrc looks like this:

# kee         


        
2条回答
  •  有刺的猬
    2021-01-17 11:41

    I ran into the same problem while customizing my prompt in zsh.

    I believe this happens because the shell interpolates the value into the string once, when the prompt is initialized. Subsequent reloads have the constant string in your prompt, not the subshell interpolation.

    Instead, put any lines that involve subshells into a variable defined with single quotes. Then interpolate that variable instead.

    autoload -U colors && colors
    
    local parse_special='%{$fg[yellow]%}$(date)%{$reset_color%}'
    
    PS1="%{$fg[green]%}%n@%m %{$fg[blue]%}%c ${parse_special} %# "
    

    Update: Adding this from ZyX's answer to make a complete solution for this. You also need to add this:

    setopt promptsubst
    

    In fact, I would suggest extracting each part of your prompt into a variable like this, including a reset_color on each. Doing so lets you change the order of prompt components without changing their implementation.

提交回复
热议问题