Skip to content

Instantly share code, notes, and snippets.

@shubham-vunet
Created March 9, 2020 12:55
Show Gist options
  • Save shubham-vunet/095feb105aeb77bc589c6f03a8784381 to your computer and use it in GitHub Desktop.
Save shubham-vunet/095feb105aeb77bc589c6f03a8784381 to your computer and use it in GitHub Desktop.

Create .bash directory

mkdir ~\.bash

Copy gitprompt file

curl -L https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh > ~\.bash\git-prompt.sh

Append these lines in .bashrc file

# GIT bash integration
if [[ -e /usr/lib/git-core/git-sh-prompt ]]; then

        source /usr/lib/git-core/git-sh-prompt

        export GIT_PS1_SHOWCOLORHINTS=true
        export GIT_PS1_SHOWDIRTYSTATE=true      # staged '+', unstaged '*'
        export GIT_PS1_SHOWUNTRACKEDFILES=true  # '%' untracked files
        export GIT_PS1_SHOWUPSTREAM="auto"      # '<' behind, '>' ahead, '<>' diverged, '=' no difference
        export GIT_PS1_SHOWSTASHSTATE=true      # '$' something is stashed

        # PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'

        function __prompt_command() {
            local ERRORCODE="$?"
            PS1="${debian_chroot:+($debian_chroot)}"

            # Errorcode (conditional)
            if [ ${ERRORCODE} != 0 ]; then
                PS1+="\e[90m    $(echo -e '\u2570\u2500\u2770')\e[1;31m$ERRORCODE\e[90m$(echo -e '\u2771')\e[0m\n"
            fi

            # Main line
            local c="$(echo -e '\u256d\u2500')"
            if [[ "$(dirs -p | wc -l)" != "1" ]] ; then
                local c="$(echo -e '\u2934') "
            fi
            PS1+="\e[90m$c\e[0m"
            if [[ ! -z "${VIRTUAL_ENV}" ]]; then
                PS1+="\e[90m$(echo -e '\u2770')\e[32m$(basename $VIRTUAL_ENV)\e[90m$(echo -e '\u2771')\e[0m"
            fi
            PS1+=" \e[33;1m\w\e[m"
            PS1+="\$(__git_ps1)"

            # Command Line
            PS1+="\n\e[90m$(echo -e '\u2570\u2500\u2bc8') \e[0m"
        }
        # use existing PS1 settings
        # PROMPT_COMMAND=$(sed -r 's|^(.+)(\\\$\s*)$|__git_ps1 "\1" "\2"|' <<< $PS1)
        PROMPT_COMMAND=__prompt_command

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