DEV Community

LG
LG

Posted on

1

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!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs