Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've recently installed zsh and took the time to configure it properly, quick overview of methods tried:

setopt prompt_subst Use prompt_subst so we can simply use the vcs_info variables and they'll be updated during run-time.

It works, with colours, and it shouldn't break anything trying to modify the PS1. however I can't seem to figure out what the downsides are for having it enabled?

psvar Use a psvar to substitute the command line, works, but messes up on colours.

update PS1 every precmd Works fine, but anything trying to modify PS1 fails as it gets reset. Could be fixed with hacks but it's too ugly/fragile IMO, so skip this one.

--

So to sum it up:

  1. What downsides are there to having prompt_subst enabled?
  2. Is there any way to make the colours work with psvar

If prompt_subst has significant downsides then 2 would be the best alternative if at all possible, 3 is a bit fragile so rather not use that.

The relevant part of my .zshrc

...

autoload -Uz vcs_info

# Needs to be enabled for the prompt to change
setopt prompt_subst

# Formats
VCS_FORMAT="%{$fg_bold[magenta]%}(%{$reset_color%}%{$fg_bold[yellow]%}%b%{$reset_color%}"
VCS_APPEND="%{$fg_bold[magenta]%})%{$reset_color%}"
VCS_NORMAL_FORMAT="${VCS_FORMAT}%{$fg_bold[magenta]%}:%{$reset_color%}%{$fg_bold[green]%}%8.8i%{$reset_color%}${VCS_APPEND}"
VCS_ACTION_FORMAT="${VCS_FORMAT}%{$fg_bold[magenta]%}:%{$reset_color%}%{$fg_bold[red]%}%a%{$reset_color%}${VCS_APPEND}"

zstyle ':vcs_info:*' enable git hg svn 
zstyle ':vcs_info:*' get-revision true

zstyle ':vcs_info:*' formats $VCS_NORMAL_FORMAT 
zstyle ':vcs_info:*' actionformats $VCS_ACTION_FORMAT

precmd () {
    vcs_info

    PS1_STR=""
    PS1_STR="${PS1_STR}%{$fg_bold[magenta]%}[%{$reset_color%}%{$fg_bold[green]%}%m%{$reset_color%}%{$fg_bold[magenta]%}]%{$reset_color%}" #hostname
    PS1_STR="${PS1_STR}%{$fg_bold[magenta]%}[%{$reset_color%}%{$fg_bold[blue]%}%n%{$reset_color%}%{$fg_bold[magenta]%}]%{$reset_color%}"  #user
    PS1_STR="${PS1_STR}%{$fg_bold[magenta]%}[%{$reset_color%}%{$fg_bold[cyan]%}%1~%{$reset_color%}%{$fg_bold[magenta]%}]%{$reset_color%}" #folder
    PS1_STR="${PS1_STR}${vcs_info_msg_0_}\$ "                                                                                             #branch/end
}   

export PS1='${PS1_STR}'

...
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.