0

I am running macOS Big Sur v11.2. I would like my zsh terminal prompt to look like this:

/directoryName/ (gitbranch) $

Thank you!

thenomadicmann
  • 492
  • 5
  • 20

1 Answers1

1

One way is use a zsh precmd to build the prompt with the vcs_info builtin. Try adding this to ~/.zshrc and restarting the terminal session:

my_precmd() {
  vcs_info
  psvar[1]=$vcs_info_msg_0_
  if [[ -n ${psvar[1]} ]]; then
    psvar[1]=" (${psvar[1]})"
  fi
}

autoload -Uz vcs_info
zstyle ':vcs_info:git:*' formats '%b'
autoload -Uz add-zsh-hook
add-zsh-hook precmd my_precmd
PROMPT='%d/%1v $ '

Some notes about the pieces are here: Different zsh terminal prompt when outside git directory

Gairfowl
  • 2,226
  • 6
  • 9
  • 1
    Thanks! I just wanted to show the current directory I'm in without the full path so I changed ````%d/%1v```` to ````/%./%1v```` – thenomadicmann Feb 12 '21 at 02:16