Colored git directory path in zsh prompt on Mac m1

The terminal on Mac OS with m1 processor is using zshell instead of bash. To change the directory path color on a zsh prompt, you will have to add configuration to the .zshrc on your home directory.

On your home directory, open the ~/.zshrc file and add the following, then restart your terminal. If the .zshrc is not there yet, create it and add the following.

#Show current git branch name on git initialized directory
parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF='%f'
COLOR_USR='%F{256}'
COLOR_DIR='%F{39}'
COLOR_GIT='%F{10}'
setopt PROMPT_SUBST
export PROMPT='${COLOR_USR}%n@%m ${COLOR_DIR}%1d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}%% '

After the above are added to the ~/.zshrc file and you have restarted the terminal. On a normal directory, the current folder name will be in blue color. On a folder initialized with git, the current folder will also be in blue color, plus the current git branch name in green color.

To change the color for the folder or the branch name, update the number for COLOR_DIR and COLOR_GIT in the code that was added in the .zshrc file.

Do a search on the internet to find out more color code for zsh if you like more color options.

Search within Codexpedia

Custom Search

Search the entire web

Custom Search