xterm-256 support for git bash - windows

I am trying to enable xterm 256 color via git bash. It turns out there are 2 ways to start a git bash in Windows.
windows cmd, run this git-cmd.exe --command=usr/bin/bash.exe -l -i
mintty, run git-bash.exe
However seems only the second one support 256 color. The following screenshot is executing result of cat AnsiColors256.ans AnsiColors256.ans.
But the downside of git-bash.exe is that it can't be integrated into integraded command line tool like ConEmu, as indicated on ConEMU Doc
Also, you may run in ConEmu tab git-bash.exe, but this is not recommended, because it runs mintty.exe, which is another terminal.
It actually start an new window instance.
My question is, is there any tweak to config cmd.exe to support 256 color like mintty.exe? I still want to use a single ConEMU instance for all my command line interfaces.
I am using windows git version git version 2.24.0.windows.2

It actually start an new window instance.
a simple "bash" would not start a new windows.
As for the CMD.exe, you might consider using instead the new Microsoft Terminal, as Microsoft/Terminal, which is more likely to support 24-bit colors.

Related

Use Windows Terminal on PhpStorm?

I would like to know how to use Windows Terminal on PhpStorm?
I went to "Settings> Terminal", and tried to change the terminal path to :
C:\Users\user\AppData\Local\Microsoft\WindowsApps\Microsoft.WindowsTerminal_8wekyb3d8bbwe\wt.exe
But no effects
I don't think it's possible: Windows Terminal is not a shell, it's a terminal emulator that has its own window/UI. It is just another front end to the existing shells that runs a shell (powershell, cmd, wsl) under the hood. PhpStorm provides its own terminal emulator in Terminal tool window. It's impossible to integrate one terminal emulator inside another, because all integration is based on parsing ANSI/VT sequences from underlying shell.

Run a shell script using Cygwin bash instead of Git Bash for Windows from Eclipse

Clicking on a .sh script inside Eclipse (on Windows) executes it using Git Bash for Windows. However, I'd like to use Cygwin bash instead.
There is an option which looks like this:
I removed the shown entry for Git Bash and added an entry with a path to the Cygwin bash executable. However, this doesn't change anything - Git Bash for Windows is still used - and after closing and opening Eclipse the Git Bash entry is there again.
How can I configure Eclipse to use Cygwin bash?
You could also use https://marketplace.eclipse.org/content/bash-editor
Here you can customize the command
A description how to launch the scripts can be found at
https://github.com/de-jcup/eclipse-bash-editor/wiki/FAQ#how-can-i-execute-shell-scripts-with-bash-editor
The plugin contains also an integrated bash debugger which should work with cygwin bash as well. For the debugger in action on a Windows 10 machine you can look at YouTube Video - Bash editor debugging on Windows 10. Here you can see the default configuration done to execut git bash. Of course you have to customize start command a bit, but I think it's feasable.
PS: I am the maintaner of the mentioned plugin

Can not install Windows Service from Bash script [duplicate]

I have a small utility script called clear.bat that does some housekeeping work on my sources.
It is a .bat file so that I could easily double-click it in Windows Explorer.
Sometimes, I find it more handy to execute it from my Git bash (msysgit, if this matters).
To do this, I type
cmd
clear.bat
exit
cmd turns my Git bash into a normal cmd window where I could easily execute my batch. When I type exit, the cmd environment is terminated and I'm back in my Git bash.
Could this be achieved in an easier way?
I tried cmd /C clean.bat since the docs say
Syntax
CMD [charset] [options]
CMD [charset] [options] [/c Command]
CMD [charset] [options] [/k Command]
Options
/C Run Command and then terminate
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables
Edit:
Just noticed that the post is broken.
What I want is to execute clean.bat from within the Git bash without having to type the three commands above (cmd, clear.bat, exit). I just want to execute the .bat file from within my Git bash. Obvious way would be to create a separate .sh file that does the same work but this will lead to double code.
Edit 2:
When I execute cmd /C clean.bat, the Git bash turns into a plain CMD environment and only displays the prompt. The file clean.bat does not get executed. It's the same as if I just type cmd.
Also, adding a /debug switch does literally nothing. Seems like only cmd gets evaluated and all further parameters are getting ignored.
After playing around a bit more, I found the solution myself:
cmd "/C clean.bat"
does the trick. But I got no clue, why...
./clear.bat will do the trick.
The Git for Windows (msysGit has been superseded by Git for Windows1) FAQ says you have 3 options:
Run programs that have problems using the winpty utility. This allows you to keep using the nicer mintty terminal, but can become unwieldy if you need the workaround for many programs.
Modify the shortcut for Git Bash to run bash directly without mintty so it uses the default console host and configure it for "Quick Edit", reasonable size and scroll-back and suitable unicode font. You'll still have to live with the other quirks of console host.
Install and use ConEmu.
At some point, Git for windows added support for the MSYS_NO_PATHCONV environment variable, so in addition to #eckes and #AlikElzin-kilaka solutions, you can also
MSYS_NO_PATHCONV=1 cmd /c clean.bat
In general, I prefer this solution, as it allows the code to be the closest to resembling normal bash, and there are many ways to export MSYS_NO_PATHCONV depending on your preferred situation.
Note: Git for Window's bash does not support the MSYS2 environment variable MSYS2_ARG_CONV_EXCL
The other solutions
The weird quoting solution
Why does cmd "/c clean.bat" not create other errors?
It turns out argument parsing in windows does not follow the same universal rules as it does in *nix. Instead, in windows the arguments are parsed differently based on the runtime you compile against. Basically in windows, the command line arguments are passed in as "one string" and then parsed by the runtime.
See here(archive) for more explanation than you could ever want.
E.g. cmd parses arguments differently then wscript.exe
In the end, you can hopefully find something that works with this method, and it is the most "window-esque" of the three solutions
The // method
This is pretty well explained here and simple to use, but adds an extra / which does not help readability
I like start clean, it opens a new window with cmd. This method has some benefits:
cmd.exe gets a native console
the new console has a native windows character encoding (e.g. cp1251 vs utf8)
This will work and it frees the terminal too
nohup ./nucleus.bat &
less nohup.out

Codeception bash color output does not display

I have been testing with Codeception and PhantomJS for a while, but when ever i have to debug and run
vendor/bin/codecept run --debug
with colors set to true all i get is:
Modules: ←[33mWebDriver, AcceptanceHelper←[39m
and so on... So for some reason the color is just outputed in a raw format and is not working at all. Colors usually work. like when i use "ls --color" it just works.
My System is Windows 7 i'm using the "git bash" and i have also tried the regular "cmd" "powershell" and "cygqwin". Neither one of them seem to work with codeceoptions output.
So what is the problem? I'm clueless :(
in bash, try running
export TERM=ansi
or
export TERM=xterm
before running your program
or, to test color output from the shell itself:
echo -e "\e[41m\e[32mCOLOR\e[0m"
if that does work than it is the program, not the environment
finally, you might just need a better console.
try conemu, it has excellent ansi color support and i use it for cmd powershell bash perl and ssh sessions :)
http://sourceforge.net/projects/conemu/
Your application (Codeception) was not adapted to Windows console, which doesn't support ANSI colorizing. To enable ANSI colors you may choose one of the following options:
ConEmu is the Windows local terminal with ANSI capabilities and many other features like tabs, splits, preconfigured shell tasks, ... Also, it's the only terminal which able to "replace" default Windows console. Yep, I'm the author.
Some applications may work properly in mintty (bundled with cygwin or msys). Many native Windows console tools can't work properly in this terminal, but may be your app will be fine.
There is AnsiCon project. It enables ANSI colorizing in standard Windows console.
BTW, bash's ls (cygwin or msys) was adapted to Windows console API, so it doesn't post ANSI to terminal, unless terminal has done special initialization of POSIX subsystem. ConEmu can do this initialization via cygwin/msys connector.

Out of a git console: how do I execute a batch file and then return to git console?

I have a small utility script called clear.bat that does some housekeeping work on my sources.
It is a .bat file so that I could easily double-click it in Windows Explorer.
Sometimes, I find it more handy to execute it from my Git bash (msysgit, if this matters).
To do this, I type
cmd
clear.bat
exit
cmd turns my Git bash into a normal cmd window where I could easily execute my batch. When I type exit, the cmd environment is terminated and I'm back in my Git bash.
Could this be achieved in an easier way?
I tried cmd /C clean.bat since the docs say
Syntax
CMD [charset] [options]
CMD [charset] [options] [/c Command]
CMD [charset] [options] [/k Command]
Options
/C Run Command and then terminate
/K Run Command and then return to the CMD prompt.
This is useful for testing, to examine variables
Edit:
Just noticed that the post is broken.
What I want is to execute clean.bat from within the Git bash without having to type the three commands above (cmd, clear.bat, exit). I just want to execute the .bat file from within my Git bash. Obvious way would be to create a separate .sh file that does the same work but this will lead to double code.
Edit 2:
When I execute cmd /C clean.bat, the Git bash turns into a plain CMD environment and only displays the prompt. The file clean.bat does not get executed. It's the same as if I just type cmd.
Also, adding a /debug switch does literally nothing. Seems like only cmd gets evaluated and all further parameters are getting ignored.
After playing around a bit more, I found the solution myself:
cmd "/C clean.bat"
does the trick. But I got no clue, why...
./clear.bat will do the trick.
The Git for Windows (msysGit has been superseded by Git for Windows1) FAQ says you have 3 options:
Run programs that have problems using the winpty utility. This allows you to keep using the nicer mintty terminal, but can become unwieldy if you need the workaround for many programs.
Modify the shortcut for Git Bash to run bash directly without mintty so it uses the default console host and configure it for "Quick Edit", reasonable size and scroll-back and suitable unicode font. You'll still have to live with the other quirks of console host.
Install and use ConEmu.
At some point, Git for windows added support for the MSYS_NO_PATHCONV environment variable, so in addition to #eckes and #AlikElzin-kilaka solutions, you can also
MSYS_NO_PATHCONV=1 cmd /c clean.bat
In general, I prefer this solution, as it allows the code to be the closest to resembling normal bash, and there are many ways to export MSYS_NO_PATHCONV depending on your preferred situation.
Note: Git for Window's bash does not support the MSYS2 environment variable MSYS2_ARG_CONV_EXCL
The other solutions
The weird quoting solution
Why does cmd "/c clean.bat" not create other errors?
It turns out argument parsing in windows does not follow the same universal rules as it does in *nix. Instead, in windows the arguments are parsed differently based on the runtime you compile against. Basically in windows, the command line arguments are passed in as "one string" and then parsed by the runtime.
See here(archive) for more explanation than you could ever want.
E.g. cmd parses arguments differently then wscript.exe
In the end, you can hopefully find something that works with this method, and it is the most "window-esque" of the three solutions
The // method
This is pretty well explained here and simple to use, but adds an extra / which does not help readability
I like start clean, it opens a new window with cmd. This method has some benefits:
cmd.exe gets a native console
the new console has a native windows character encoding (e.g. cp1251 vs utf8)
This will work and it frees the terminal too
nohup ./nucleus.bat &
less nohup.out

Resources