Replacing Command Prompt with Git Bash

Windows built in Command Prompt is ugly and dated. It also lacks proper Git integration. Git for Windows comes with a configured Git Bash you can use instead. Combine that with Mintty and you now have a full featured themeable terminal rivaling the built in Mac OS Terminal.

Git Bash

In the Git for Windows installer choose Use MinTTY when asked to configure the default emulator. This will allow you to apply a custom theme. In addition:

  • Mintty has much better support for non-english characters (UTF-8)
  • Git branch name in the terminal prompt after teh current path
  • Mintty is based on PuTTY
  • It can run fullscreen (yay).

Using Git Bash with a Custom Theme

Open Git Bash, right click on the title bar and select Options…. You’ll see Theme select box. There’s no need to setup the theme manually color by color. Get one of the base16 color schemes from oumu/mintty-color-schemes.

  • Download the themes.
  • Select the one you like. I prefer the Monokai flavor – base16-monokai-mod.minttyrc
  • Open Git Bash options again and drag & drop the selected *.minttyrc file in the Theme select box.
  • Hit Apply or Save, close and reopen Git Bash

Git Bash with base16 Monokai theme

You’ll see the new theme applied to the terminal. Looks much better, doesn’t it?

How about some transparency?

In addition the the custom theme I like turning on light transparency when the terminal window is inactive.

Git Bash: Transparency

Removing MINGW64 from Title and Prompt

No one likes the MINGW32 or MINGW64 showing in the prompt. It just strains the eye with useless text. Let’s remove it. In Windows Explorer open the following folder:

📂 C:\Program Files\Git\etc\profile.d\

  • You’ll find a file named git-prompt.sh. Open it in an editor (Notepad++, Sublime, Visual Studio Code).
    Create a backup copy just in case something goes wrong.

  • Look for the following two lines which add the MINGW64 text in the prompt and delete them:

    PS1="$PS1"'\[\033[35m\]'       # change to purple
    PS1="$PS1"'$MSYSTEM '          # show MSYSTEM
    
  • Let’s change the title as well. Find the following near the top:
    TITLEPREFIX=$MSYSTEM
    

    Change to the title you want. I like setting this to “Git Bash“:

    TITLEPREFIX='Git Bash'
    

    Single quotes around the value are !important. Don’t miss them.

git-prompt.sh

NOTE: If git-prompt.sh is invalid Git Bash crashes and starts creating infinite processes. In this happens restart and then edit the file again. If the issue persist replace the file with the original copy.

Opening bat files the cmd way

One of the downsides of Mintty is that you need to open bat files by writing the full extension. Let’s make the extension optional. We want to able to open example.bat by just writing example.

What we need is to add a fallback that checks for bat files when there’s existing no command to execute. We can do that by adding command_not_found_handle to .barchrc.

  • Open C:\Program Files\Git\etc\bash.bashrc in an editor. Scroll to the bottom and add the necessary handler:
    # CUSTOM
    # Open bat files without writing the extension
    command_not_found_handle() {
        if cmd.exe /c "(where $1 || (help $1 |find /V \"/?\")) >nul 2>nul && ($* || exit 0)"; then
            return $?
        else
            if [ -x /usr/lib/command-not-found ]; then
               /usr/lib/command-not-found -- "$1"
               return $?
            elif [ -x /usr/share/command-not-found/command-not-found ]; then
               /usr/share/command-not-found/command-not-found -- "$1"
               return $?
            else
               printf "%s: command not found\n" "$1" >&2
               return 127
            fi
        fi
    }
    
  • Save the file and close all opened git bash consoles

  • Reopen and try executing a bat file without writing the extension

Nodejs and gulp coloring in MINGW

There’s an issue with MINGW and nodejs console output coloring. It’s most noticeable if you are using gulp or grunt. Text will be plain white instead of using the chalk colors that were set.

Fix that by creating a new Windows environment variable FORCE_COLOR with value YES.

Final Result

Git Bash with Monokai theme

Not enough or you need tabs?

There are other options out there if you need tabs or opening more than one terminal type at once. They take more memory though, so the solution won’t be as lightweight as using Git Bash.

  • Cmder: Uses ConnEmu. Has a nice default theme and allows opening various terminals
  • Hyper: Terminal emulator written with Electron and Nodejs. The plugins system is quite promising.
  • PowerShell: Comes built in with Windows 10. Do install Posh Git for better Git integration.

Using command prompt on Windows doesn’t need to be ugly and unpleasant. Try it yourself.

One thought on “Replacing Command Prompt with Git Bash

Leave a Reply

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