DEV Community

Discussion on: Git Prompt in Bash

Collapse
 
brandonwallace profile image
brandon_wallace

This is what I came up with. Thanks for this post Vlastimil.

blu='\[\033[01;34m\]'
pur='\[\033[01;35m\]'
blu='\[\033[01;36m\]'
wht='\[\033[01;37m\]'
ylw='\[\033[01;33m\]'
grn='\[\033[01;32m\]'
red='\[\033[01;31m\]'
blk='\[\033[01;30m\]'
clr='\[\033[01;00m\]'

# Run git branch if there is a .git directory present.
# Display current status of the git repository.
function git_branch() {
    if [ -d .git ] ; then
        GITSTATUS=$(git status | awk '
        /^Changes not staged/{printf("+")} 
        /^Untracked files/{printf("*")} 
        /^Changes not staged/{printf("?")} 
        /^Your branch is ahead of/{printf("^")}')
        printf "%s" "($(git branch 2> /dev/null | awk '/\*/{print $2}'))${GITSTATUS}";
    fi
}

PS1='${debian_chroot:+($debian_chroot)}'${blu}'$(git_branch)'${pur}' \W'${grn}' \$ '${clr}
Enter fullscreen mode Exit fullscreen mode