[英]How do I get colorized output on my windows git-bash terminal?
Uninstall Git Bash for Windows 10 and run the installer again:卸载适用于 Windows 10 的 Git Bash 并再次运行安装程序:
Test if it works correctly:测试它是否正常工作:
ls
you'll see all folder colored in blue打开 Git Bash(cmd 会打开),尝试使用ls
你会看到所有文件夹都变成蓝色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通过运行echo -e "\\033[44m\\033[37m Test \\033[0m"
尝试一些ANSI 转义码,您将看到带有蓝色背景的文本Test ,如下面的屏幕截图所示Windows 10 Console support 24-bit color and ANSI escape sequences Windows 10 控制台支持24 位颜色和ANSI 转义序列
The terminal was a MinTTY, which does not support colors it seems.终端是一个 MinTTY,它似乎不支持颜色。 Fixed it by re-installing and ticking of Windows Terminal.通过重新安装和勾选 Windows 终端来修复它。
For me, it was choosing Windows default console window instead of MinTTY that made color output not working.对我来说,是选择Windows 默认控制台窗口而不是MinTTY导致颜色输出不起作用。
My solution:我的解决方案:
git bash
;卸载git bash
; during installing, choose MinTTY (the default option).在安装过程中,选择MinTTY (默认选项)。C:\\Program Files\\Git\\etc
, open your git bash安装后,转到C:\\Program Files\\Git\\etc
,打开你的 git bashvim ~/.bashrc
(for some reason using an editor doesn't work; I guess it's a privilege issue) vim ~/.bashrc
(由于某种原因使用编辑器不起作用;我想这是一个权限问题)# Add colors to 'ls'
change it to alias ls='ls --color=auto'
在# Add colors to 'ls'
将其更改为alias ls='ls --color=auto'
Then restart and it should work.然后重新启动,它应该可以工作。
My version: git version 2.24.1.windows.2我的版本:git 版本 2.24.1.windows.2
winpty
使用winpty
Windows Git Bash has some documented quirks: Winpty and Git Bash Windows Git Bash 有一些记录在案的怪癖: Winpty 和 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.再次是另一个 windows / git bash 怪癖,它不会尝试解析以.cmd
结尾的可执行文件,因此它需要轻推。
$ winpty npm.cmd start
The same applies for yarn
with:这同样适用于yarn
:
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:虽然我们在这里,你有麻烦gyp
找到您Python2安装位置编译原生扩展,然后试试这个:
env PYTHON=/c/Python27/ winpty yarn.cmd install
Git Bash overrides your PYTHON
environment variable for only the duration of this command. Git Bash 仅在此命令的持续时间内覆盖您的PYTHON
环境变量。 You get winpty
to run the pseudo-tty session to allow animation rendering and coloring.您可以通过winpty
运行伪 tty 会话以允许动画渲染和着色。
Assuming your python 2 install location is C:\\Python27假设你的 python 2 安装位置是 C:\\Python27
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.