ansicon
ansicon copied to clipboard
Windows Mingw32 Git Bash: only git is colored
I've installed Ansicon 1.66 using the x64 ansicon.exe -i. I can see the AutoRun key in the registry has changed to use Ansicon. I'm on Windows 7 Pro x64.
I use Git Bash (Mingw32) to work on my projects with Git, PHPUnit, Behat and others.
I recently installed Ansicon and it worked perfectly in GitBash and cmd.exe! Then after a few reboots it didn't. I've been on and off trying to solve what is going on but can't figure it out.
I've noticed the following:
- Only
gitcommands receive proper coloring. - Any other types of commands (
phpunit,behat,ls, etc.) do not receive any coloring, but are not garbled with visible escape codes either (even with forced coloring). - Same problem with
cmd.exe: only Git receives color.
I also noticed that only when I use cmd.exe the ansicon.log seems to be populated. Is this expected behaviour?
Why would it work and then suddenly just not work?
If you need any more info please ask.
EDIT: Somewhere I read that I need to set a TERM environment variable to something. Could this affect the issue at hand?
Alrighty, Ansicon itself seems to be working. After directly starting ansicon.exe without any parameters (e.g. it starts cmd.exe), then browsing to Git bin and starting sh.exe via
sh.exe --login -i
then I get PHPUnit colors inside the command line. A quirk in here is that when I start ansicon.exe and use the cmd.exe without running sh.exe PHPUnit does not show any colors.
Isn't this what the AutoRun thingie should do for me automatically? E.g.
- Start Git bash
sh.exe sh.exeis proxied tocmd.exe- Before
cmd.exestarts it is run throughansicon.exe.
Maybe I could make a batch file for this in the mean time. Any suggestions as to why the automatic wrapping is not working would be helpful.
EDIT:
Here's the .bat I now use and makes everything colorful:
@echo off
set ComSpec=C:\Git\bin\sh.exe --login -i
C:\Ansicon\x64\ansicon.exe
Sets the ComSpec to use GitBash instead of cmd.exe and then runs ansicon.exe which executes the ComSpec prompt.
The Git Bash shortcut runs sh.exe directly, there is no cmd.exe proxy. Modifying your shortcut to prefix with ansicon (or cmd) should do the trick. You may also be able to add ansicon -p to your Startup group (or it might need a registry Run entry) to hook into Explorer directly (a future version will provide this option). Git commands (anything compiled with MSYS) process escape sequences themselves.
I see. I was just wondering why it suddenly stopped working on my system's Git Bash.
I tried to add ansicon.exe -p to my .bashrc and .profile files, but they didn't work. Running ansicon.exe -p inside a running Gitbash or CMD session makes no difference either from what I can gather.
Do you mean I can hook Ansicon to my explorer.exe which in turn makes all prompts use it?
My .bat quickfix works well otherwise, but running some commands that seem need the "stock" ComSpec variable (e.g. npm install) are broken. Nothing overly horrible, minor annoyance.
The problem within Bash is described here.
That's the intention with regards Explorer. IIRC it did work with the Run entry, but I haven't tried through Startup.
Your batch can simply be C:\Ansicon\x64\ansicon.exe C:\Git\bin\sh.exe --login -i.
I see. One thing that keeps bugging me is that ansicon.exe -p does not work inside a regular cmd.exe either. The only way I can use Ansicon is by launching ansicon.exe first and then starting sh.exe inside it.
Tried that batch and it does work, thanks. :)
ansicon -p is how the DLL gets injected into the parent CMD in the first place, so if that's no longer working, that would explain why it stopped working after the reboots. Let's try a fresh approach: use the Run dialog to run cmd /d - that bypasses everything in Autorun, and as another check, set ANSICON should be undefined. Now do set ANSICON_LOG=5, ansicon -p and view the log (%TEMP%\ansicon.log), which should look something like:
ANSICON (64-bit) v1.66 log (5) started 2015-09-25 13:11:31
ansicon (9000): cmd.exe (9512)
ansicon (9000): 64-bit console (base = 000000004A390000)
cmd (9512): hDllInstance = 00000000AC000000
cmd (9512): WriteConsoleW: 2 "\r\n"
cmd (9512): WriteConsoleW: 15 "C:\Users\Jason>"
cmd (9512): WriteConsoleW: 1 "\n"
...
If you don't see that, report back what you do see...