Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.5k views
in Technique[技术] by (71.8m points)

How to correctly enable ANSI colors in ConEmu + Git Bash?

I'm using Git Bash with ConEmu to make it look cool. However, upon installing Composer the colors seem to be escaped:

enter image description here

So Git Bash does not support all the colors. Checking the AnsiColors256.ans file:

enter image description here

After lots of Googling, I still haven't found any solution. I don't want to use Ansicon or other console emulator, ConEmu is fine for me.

My settings:

  • Inject ConEmuHk enabled
  • Ansi X3.64 / xterm 256 enabled
  • Windows 7 x64
  • Git Bash 1.9.5
  • ConEmu 141208

How do I enable all the colors? This is annoying my need for a Console-Zen experience :(

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To correctly enable colors in Git Bash :

  1. Download and extract ANSICON : https://github.com/adoxa/ansicon/releases/tag/v1.81
  2. If you are running 64-bit OS, copy everything inside x64 folder, Otherwise,
    • If you are running 32-bit OS, copy everything inside x86 folder.
  3. Create a folder ANSICON at C:Program FilesANSICON and paste the copied contents here.
  4. Right click on your Git Bash shortcut and go to properties.

enter image description here

  1. Set/Modify Target value to following (refer to the screenshot below) :

"C:Program FilesANSICONansicon.exe" "C:Program FilesGitgit-bash.exe" --cd-to-home

Modify shortcut target

  1. Open your .bashrc file (C:UsersAditya.bashrc).

NOTE: .bashrc is a hidden file. So you need to turn on the option in your windows explorer settings to display hidden files.

  1. Add following 2 lines to your .bashrc file (anywhere) :

unalias $(alias | grep winpty | grep php | cut -d"=" -f1 | cut -d" " -f2)

export ANSICON=true

enter image description here

  1. Save your .bashrc file and open Git Bash now. Done! composer command output php artisan colored output - very tricky to get

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...