Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get colorized output on my windows git-bash terminal?

How do I get colorized highlighting on the output?
e.g

npm start  
npm test
etc.

npm start example

System:
Windows 10
Git version 2.16.1.windows.4
Node 5.6.0

like image 743
Duy Avatar asked Feb 12 '18 15:02

Duy


4 Answers

Uninstall Git Bash for Windows 10 and run the installer again:

  • Click next until you'll prompt to choose to Configure the terminal emulator to use with Git Bash, here you select Use Windows default console window (instead of the default option which use MinTTY as terminal emulator)
  • Click next and finish the installation

Test if it works correctly:

  • Open Git Bash (cmd will open up), try to use ls you'll see all folder colored in blue
  • Try some ANSI escape code by running echo -e "\033[44m\033[37m Test \033[0m" you'll se the text Test with a blue background as seen in the screenshot below

enter image description here

Windows 10 Console support 24-bit color and ANSI escape sequences

like image 139
pldg Avatar answered Oct 21 '22 15:10

pldg


The terminal was a MinTTY, which does not support colors it seems. Fixed it by re-installing and ticking of Windows Terminal.

like image 8
Duy Avatar answered Oct 21 '22 16:10

Duy


For me, it was choosing Windows default console window instead of MinTTY that made color output not working.

My solution:

  1. Uninstall git bash; during installing, choose MinTTY (the default option).
  2. After installation, head over to C:\Program Files\Git\etc, open your git bash
  3. vim ~/.bashrc (for some reason using an editor doesn't work; I guess it's a privilege issue)
  4. Under # Add colors to 'ls' change it to alias ls='ls --color=auto'

Then restart and it should work.

My version: git version 2.24.1.windows.2

like image 6
kohane15 Avatar answered Oct 21 '22 15:10

kohane15


Use winpty

Windows Git Bash has some documented quirks: Winpty and Git Bash

$ winpty npm start
winpty: error: cannot start 'npm': Not found in PATH

Again another windows / git bash quirk, it doesn't attempt to resolve executables ending in .cmd so it needs a nudge.

$ winpty npm.cmd start

The same applies for yarn with:

winpty yarn.cmd start

While we are here and you are having trouble getting gyp to locate your Python2 install location to compile native extensions then try this:

env PYTHON=/c/Python27/ winpty yarn.cmd install

Git Bash overrides your PYTHON environment variable for only the duration of this command. You get winpty to run the pseudo-tty session to allow animation rendering and coloring.

Assuming your python 2 install location is C:\Python27

like image 1
Josh Peak Avatar answered Oct 21 '22 17:10

Josh Peak