Reputation: 2461
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 load the terminal and start at ~
(the home directory). zsh prompt should read
hostname:username @ user $
cd dev/repo
takes me into a git repo, zsh prompt should read
hostname:username @ repo $ (master)
cd ..
takes me back to dev
, which isn't a git repo, prompt should read
hostname:username @ dev $
The prompt never changes / updates automatically; I have to run source ~/.zshrc
to make the prompt update as I change directories.
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!
Upvotes: 17
Views: 5104
Reputation: 2978
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"
}
Upvotes: 3
Reputation: 2461
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_}'
Upvotes: 39