Created
June 1, 2012 18:25
-
-
Save fstrube/2854183 to your computer and use it in GitHub Desktop.
Place your git branch name and status in your Bash / Terminal prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
silly me...if you have bash autocompletion setup for git, then you can just call the __git_ps1 function in your prompt variable!