Git Bash: Shell prompt customization

What is it?

Git Bash for Windows is not just bash compiled for Windows. It is a package that contains bash, which is a command-line shell, and a collection of other, separate *nix utilities which you can run using the shell, compiled for Windows, and a new command-line interface terminal window called mintty.

You can download it from here.

Shell prompt customization

If we want to customize the shell prompt according to our preferences, we just need to edit the file “git-prompt.sh”. In a Windows x64 system, we can find it in:

C:\Program Files\Git\etc\profile.d\git-prompt.sh

Now we just need to play a little bit with the different options available.

As an example, the version I am using right now looks like that:

TITLEPREFIX='Bash Prompt (Git for Windows) =>'

PS1='\[\033]0;$TITLEPREFIX:${PWD//[^[:ascii:]]/?}\007\]' # set window title
PS1="$PS1"'\[\033[32m\]'       # change to green
PS1="$PS1"'\w'                 # current working directory
if test -z "$WINELOADERNOEXEC"
then
    GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
    COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
    COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
    COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
    if test -f "$COMPLETION_PATH/git-prompt.sh"
    then
        . "$COMPLETION_PATH/git-completion.bash"
        . "$COMPLETION_PATH/git-prompt.sh"
        PS1="$PS1"'\[\033[36m\]'  # change color to cyan
        PS1="$PS1"'`__git_ps1`'   # bash function
    fi
fi
PS1="$PS1"'\[\033[0m\]'        # change color
PS1="$PS1"'$ '                 # prompt: always $
MSYS2_PS1="$PS1"               # for detection by MSYS2 SDK's bash.basrc
Git Bash: Shell prompt customization

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.