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

Lukas GaucasLukas Gaucas
1 min read

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$ '

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!

0
Subscribe to my newsletter

Read articles from Lukas Gaucas directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lukas Gaucas
Lukas Gaucas

Self-employed digital nomad at your service Currently working on: CosmosPWA@https://youtube.com/playlist?list=PL7JUsQnnxGCsAJa76T6zVnpnIT5osS9MZ&si=6qlfHepvj0j7vPYM