DEV Community

Lukas Gaucas
Lukas Gaucas

Posted on

Git bash for Windows users PS1 variable (aka prompt) customization

This assumes that you are located in %USERPROFILE% (File Explorer), otherwise, init Git bash for Windows shell session at cd ~: once you are there, touch .bash_profile via Git the bash session. Following these third-party guidelines (see link) we can customize our PS1 as we want to:

MY_ALIAS="vanillacamp"
export PS1='\e[0;32m$MY_ALIAS@\[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '
Enter fullscreen mode Exit fullscreen mode

Let's clarify the snippet above:

  • MY_ALIAS is a bash variable, that later on will be referred to using a dollar sign as the following: $MY_ALIAS

  • the export keyword makes sure the PS1 will be valid among sessions (system-wise)

  • PS1 variables follow ANSI-escaping standards for colouring and formatting including some special escape sequences such as \u for system (admin) username, or relevant

  • the $MSYSTEM is part of MSYS2 toolchain; depending on platform $MSYSTEM most likely be one of the following values: MINGW32|MINGW64|MSYS

  • __git_ps1 is part of Git version control that, essentially, provides the current branch as part of your prompt, thus PS1 variable you currently trying to modify

Happy modifying, cheers!

Top comments (0)