9

I have following code in my .zshrc file. When I go to my repos and the git branch name is not showing up on the right side of the console until I source the .zshrc file with

source ~/.zshrc

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

RPS1=`parse_git_branch`
Aron Lee
  • 607
  • 1
  • 5
  • 8

2 Answers2

3

I would recommend you use Oh-My-Zsh

https://github.com/robbyrussell/oh-my-zsh

It has great options and git support out of the box (branch names, coloring, stash...)

Renato C.
  • 47
  • 1
  • 3
    I agree, the link is great, but could you please provide more details from the link... – EugenSunic Jan 26 '18 at 20:10
  • zshrc is a cool tool but with 250+ plugins business security sometimes blocks its usage. Any idea how to do without the tools? – iDev Oct 21 '22 at 17:59
2

You can use vcs_info:

autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' formats '(%b)'
precmd() { vcs_info }
setopt prompt_subst
RPROMPT='${vcs_info_msg_0_}'

This is already included with zsh.

Constantin
  • 21
  • 2