Skip to content

Instantly share code, notes, and snippets.

@RxDx
Created May 6, 2026 22:59
Show Gist options
  • Select an option

  • Save RxDx/184cae703cab9573c21874051bda127b to your computer and use it in GitHub Desktop.

Select an option

Save RxDx/184cae703cab9573c21874051bda127b to your computer and use it in GitHub Desktop.
Bash PROMPT
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF='%f'
COLOR_USR='%F{243}'
COLOR_DIR='%F{39}'
COLOR_GIT='%F{197}'
# About the prefixed `$`: https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html#:~:text=Words%20in%20the%20form%20%22%24',by%20the%20ANSI%2DC%20standard.
NEWLINE=$'\n'
# Set zsh option for prompt substitution
setopt PROMPT_SUBST
export PROMPT='${COLOR_USR}%n@%M ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}${NEWLINE}%% '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment