Skip to content

maabiddevra/gitcolorbash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

gitcolorbash

Color bash and show git branch

  • Open ~/.bash_profile and add the below code, code can also be added in ~/.bashrc
parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}


function branch_status {
    branch=`branch`
    [ -n "$branch" ] && echo " ($branch)`dirty_status`" || echo
}

function branch {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}

function dirty_status {
    git status --porcelain | (
        unset dirty deleted untracked newfile copied renamed
        while read line ; do
            case "${line//[[:space:]]/}" in
                'M'*)          dirty='!' ; ;;
                'UU'*)         dirty='!' ; ;;
                'D'*)          deleted='x' ; ;;
                '??'*)         untracked='?' ; ;;
                'A'*)          newfile='+' ; ;;
                'C'*)          copied='*' ; ;;
                'R'*)          renamed='>' ; ;;
            esac
        done
        bits="$dirty$deleted$untracked$newfile$copied$renamed"
        [ -n "$bits" ] && echo "[$bits]" || echo
    )
}

export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(branch_status)\[\033[00m\] \n$ "
  • Restart the terminal

About

Color bash and show git branch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published