Skip to content

Instantly share code, notes, and snippets.

@fstrube
Created June 1, 2012 18:25
Show Gist options
  • Save fstrube/2854183 to your computer and use it in GitHub Desktop.
Save fstrube/2854183 to your computer and use it in GitHub Desktop.
Place your git branch name and status in your Bash / Terminal prompt
# Adding git-specific info to prompt
update_git_cwd() {
if git status > /dev/null 2>&1 && local BRANCH=`git branch | grep '^*' | cut -c3-`; then
if ! git status 2>/dev/null | grep 'working directory clean' > /dev/null 2>&1 ; then
BRANCH="$BRANCH\033[31m*"
fi
PS1=`printf '[local:\W (\033[32m%s\033[0m)] \$ ' "$BRANCH"`
else
PS1='[local:\W ] \$ '
fi
}
PROMPT_COMMAND="update_git_cwd; $PROMPT_COMMAND"
@fstrube
Copy link
Author

fstrube commented Jun 1, 2012

silly me...if you have bash autocompletion setup for git, then you can just call the __git_ps1 function in your prompt variable!

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