zsh not updating vcs_info
Asked Answered
P

2

17

I'm just trying to show the current branch of the git repository I'm inside (if available) by using vcs_info. The relevant portion of my .zshrc file is as follows:

autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats "%F{010}(%b)%f "

precmd() { vcs_info }
setopt prompt_subst

PROMPT="%F{226}%m:%n @ %F{214}%1d %F{226}\$%f ${vcs_info_msg_0_}"

I expect:

  1. I load the terminal and start at ~ (the home directory). zsh prompt should read

    hostname:username @ user $

  2. cd dev/repo takes me into a git repo, zsh prompt should read

    hostname:username @ repo $ (master)

  3. cd .. takes me back to dev, which isn't a git repo, prompt should read

    hostname:username @ dev $

I experience:

The prompt never changes / updates automatically; I have to run source ~/.zshrc to make the prompt update as I change directories.

What I have tried:

I've tried updating the precmd() block to be as follows:

precmd() {
    vcs_info
    echo "This has been executed"
}

And I see This has been executed right before every prompt, so I know that the precmd block is being entered correctly. It seems that the vcs_info just isn't working.

Perhaps I'm missing something; can someone point out what the issue could be? Thanks!

Papageno answered 4/6, 2019 at 18:3 Comment(1)
I ended up putting the PROMPT assignment inside the precmd methodIchang
P
39

Figured it out by happenstance a few months later after not really caring... the prompt has to use single quotes instead of double-quotes.

PROMPT='%F{226}%m:%n @ %F{214}%1d %F{226}\$%f ${vcs_info_msg_0_}'

Papageno answered 10/8, 2019 at 5:36 Comment(5)
That is it! double-quotes now are buggy. Thank you, you saved my day.Woodworm
With single quotes I see a literal "${vcs_info_msg_0_}" in the prompt.Numen
@CrisLuengo - make sure you have prompt substitutions enabled with setopt prompt_substPigweed
For me it's the other way around, double quotes are not working and just printing ${vcs_info_msg_0_} as plain-text while double-quotes work but don't update the branch nameIchang
@RaulRene I got the same behaviorAnselm
A
3

Putting the whole thing inside the precmd() worked

autoload -Uz vcs_info
precmd() {
  vcs_info
  # Format the vcs_info_msg_0_ variable
  zstyle ":vcs_info:git:*" formats "(%b) "

  echo -e -n "\x1b[\x33 q"
  PROMPT="%B%1~ $%b %F{004}${vcs_info_msg_0_}%f> "
  RPROMPT=" %F{005}%T%f"
}
Anselm answered 1/6, 2022 at 14:25 Comment(2)
Regarding single vs double quotes. Single quotes had been working the previous day for me while they didn't worked anymore the next. Not sure what is the root cause behind that part of the bug, but the behavior seems fairly inconsistent when reading other comments in this question. I hope someone improves this question with an answer addressing that.Anselm
Quotes made no difference for me, but putting the variables in the precmd worked perfectly, thanks.Cattleman

© 2022 - 2024 — McMap. All rights reserved.