- Catalina
- Big Sur
- Monterey
- Ventura
- Sonoma
Open ~/.zshrc
in your favorite editor and add the following content to the bottom.
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF=$'%f'
COLOR_USR=$'%F{243}'
COLOR_DIR=$'%F{197}'
COLOR_GIT=$'%F{39}'
setopt PROMPT_SUBST
export PROMPT='${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ '
To reload and apply adjustments to the formatting use source ~/.zshrc
in the zsh shell.
- Thank you benP2ER for the useful additions in his comment
- Original gist by Jose Quintana: Add Git Branch Name to Terminal Prompt (Linux/Mac)
Thanks for the reply.
When I installed nvm via Homebrew, I got these 3 items created
.zprofile
.zsh_history
.zsh__sessions (folder)
I thought .zshrc would be one of them (It's been a while since last time I've done this for a new machine!), but since it wasn't there, I've done some research and found out that .zshrc and .zprofile should be the same: I guess they are not!
I'll try create a .zshrc manually then.