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

六月ゝ 毕业季﹏ 提交于 2019-11-30 15:02:44

问题


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

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

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 :(


回答1:


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 Files\ANSICON and paste the copied contents here.
  4. Right click on your Git Bash shortcut and go to properties.

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

"C:\Program Files\ANSICON\ansicon.exe" "C:\Program Files\Git\git-bash.exe" --cd-to-home

  1. Open your .bashrc file (C:\Users\Aditya\.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

  1. Save your .bashrc file and open Git Bash now. Done!



回答2:


Run ConEmu from WinR (type full path to sh.exe if needed)

ConEmu -basic -cmd sh.exe -l -i

Run composer, ANSI is working.




回答3:


Another problem you may encounter is if you set up the task (Settings → Startup → Tasks) without proper quoting. Having a task like the following will break ANSI coloring of composer (everything else seems to work just fine):

%TOOLS_DIR%\git\bin\sh.exe --login -i -new_console:C:%TOOLS_DIR%\git\mingw64\share\git\git-for-windows.ico:t:"Git bash"

The value of %TOOLS_DIR% is D:\Tools. I can only imagine that the backslashes are the problem. however, the following works as expected:

"%TOOLS_DIR%\git\bin\sh.exe" --login -i -new_console:C:"%TOOLS_DIR%\git\mingw64\share\git\git-for-windows.ico":t:"Git bash"


来源:https://stackoverflow.com/questions/27580668/how-to-correctly-enable-ansi-colors-in-conemu-git-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!