Skip to content

Instantly share code, notes, and snippets.

@philchristensen
Created December 19, 2010 20:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philchristensen/747661 to your computer and use it in GitHub Desktop.
Save philchristensen/747661 to your computer and use it in GitHub Desktop.
add current git branch to shell prompt
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "#"${ref#refs/heads/}
}
export PS1="\u@\h:\w\[\e[31;40m\]\$(parse_git_branch)\[\e[0m\] \$ "
@philchristensen
Copy link
Author

To make this update on every prompt (like when changing dirs), you'll want to tie it into PROMPT_COMMAND

function decorate_prompt {
  export PS1="\u@\h:\w\[\e[31;40m\]\$(parse_git_branch)\[\e[0m\] \$ "
}
export PROMPT_COMMAND=decorate_prompt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment