Skip to content

Instantly share code, notes, and snippets.

@Thilakeswar
Created June 23, 2023 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thilakeswar/6d0a413613a0e01d5408ee7fdf51d5dc to your computer and use it in GitHub Desktop.
Save Thilakeswar/6d0a413613a0e01d5408ee7fdf51d5dc to your computer and use it in GitHub Desktop.
Git Branch name in Terminal path
#According to Apple,
#zsh (Z shell) is the default shell for all newly created user accounts, starting with macOS Catalina.
#Run the command 'echo $SHELL' to find your default shell.
#If result is '/bin/bash', then bash is the default shell else if result is '/bin/zsh', then it's zsh
#Copy the code mentioned below,
#in '~/.bashrc' if bash is your default shell
#in '~/.zshrc' if zsh is your default shell
#Code to be copied starts after >>>> and ends before <<<<
>>>>
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
setopt PROMPT_SUBST
#export PROMPT='%F{grey}%n%f %F{cyan}%~%f %F{green}$(parse_git_branch)%f %F{normal}$%f '
export PROMPT='%F{cyan}%~%f %F{green}$(parse_git_branch)%f %F{normal}$%f '
<<<<
#You could see two export PROMPT lines in the above code.
#Uncomment the first and comment the second, if you need the user name to displayed before the directory path.
#I have used the colors as per my choice and which is also appealing. If you need, you can modify the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment