Skip to content

Instantly share code, notes, and snippets.

@reinaldo-z
Created August 11, 2014 20:48
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 reinaldo-z/27ce4047f536ce5b88c1 to your computer and use it in GitHub Desktop.
Save reinaldo-z/27ce4047f536ce5b88c1 to your computer and use it in GitHub Desktop.
Add git branch and status to your prompt
#PROMPT PERSONALIZATION
#Add the following lines to the ~/.bashrc file.
#If your actual working directory corresponds to a git repo will be displayed the branch name and the statuss: up to date (only the name of the branch), dirty (branch name + "*"), need to commit (branch name +" <-- comm"), and need to push to origin (branch name +" --> Or").
function check_branch {
gs=$(git status 2> /dev/null)
if [[ -z "$gs" ]]; then
BRANCH=""
elif [[ `echo "$gs" | grep -w 'reset HEAD' | wc -l` == 1 ]]; then
BRANCH="["`git branch | grep \* | cut -c 3-`" <-- comm] "
elif [[ `echo "$gs" | grep -w 'push\|nothing'| wc -l` == 2 ]]; then
BRANCH="["`git branch | grep \* | cut -c 3-`" --> Or] "
elif [[ `echo "$gs" | grep nothing | wc -l` == 1 ]]; then
BRANCH="["`git branch | grep \* | cut -c 3-`"] "
else
BRANCH="["`git branch | grep \* | cut -c 3-`"*] "
fi
echo "$BRANCH"
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h: \[\033[00;31m\]$(check_branch)\[\033[01;34m\]\W \$\[\033[00m\] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment