Skip to content

Instantly share code, notes, and snippets.

@JackNicholas
Created December 27, 2013 08:07
Show Gist options
  • Save JackNicholas/8143973 to your computer and use it in GitHub Desktop.
Save JackNicholas/8143973 to your computer and use it in GitHub Desktop.
Adding name of current git branch to command line prompt
You can test command line prompts with commands like
export PS1="\W \u \$ “
(then save to .bashrc or .bash_profile if want it permanently)
Make sure that path is up to date.
export PATH=/usr/local/bin:$PATH
The script and commands to add a coloured branch name to the prompt: Save this to .bashrc or .bash_profile
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ “
Refresh terminal to make sure it works:
source ~/.bash_profile
Thanks to:
http://beckism.com/2009/02/better_bash_prompt/
http://martinfitzpatrick.name/article/add-git-branch-name-to-terminal-prompt-mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment