我试图添加一个新的终端(Git Bash)到新的Windows终端。然而,我不能让它工作。

我尝试将profiles数组中的命令行属性更改为git-bash.exe,但没有运气。

有人知道怎么让它工作吗?


当前回答

添加“%PROGRAMFILES%\\Git\\bin\\bash.exe -l -i”对我不起作用。由于%PROGRAMFILES中的空格符号(在cmd中为分隔符),%终端执行命令“C:\Program”而不是“C:\Program Files\Git\bin\bash.exe -l -i”。解决方案应该是在json文件中添加引号,但我不知道如何。 唯一的解决方案是将“C:\Program Files\Git\bin”添加到%PATH%,并在profiles.json中写入“commandline”:“bash.exe”

其他回答

因为大多数答案要么显示大量不相关的配置,要么不显示配置,所以我创建了自己的答案,试图更集中。它主要是基于配置文件设置参考和阿基米德特拉哈诺的答案。

步骤

Open PowerShell and enter [guid]::NewGuid() to generate a new GUID. We will use it at step 3. > [guid]::NewGuid() Guid ---- a3da8d92-2f3f-4e36-9714-98876b6cb480 Open the settings of Windows Terminal. (CTRL+,) Add the following JSON object to profiles.list. Replace guid with the one you generated at step 1. { "guid": "{a3da8d92-2f3f-4e36-9714-98876b6cb480}", "name": "Git Bash", "commandline": "\"%PROGRAMFILES%\\Git\\usr\\bin\\bash.exe\" -i -l", "icon": "%PROGRAMFILES%\\Git\\mingw64\\share\\git\\git-for-windows.ico", "startingDirectory" : "%USERPROFILE%" },

笔记

There is currently an issue that you cannot use your arrow keys (and some other keys). It seems to work with the latest preview version, though. (issue #6859) Specifying "startingDirectory" : "%USERPROFILE%" shouldn't be necessary according to the reference. However, if I don't specify it, the starting directory was different depending on how I started the terminal initially. Settings that shall apply to all terminals can be specified in profiles.defaults. I recommend to set "antialiasingMode": "cleartype" in profiles.defaults. You have to remove "useAcrylic" (if you have added it as suggested by some other answers) to make it work. It improves the quality of text rendering. However, you cannot have transparent background without useAcrylic. See issue #1298. If you have problems with the cursor, you can try another shape like "cursorShape": "filledBox". See cursor settings for more information.

对于那些可能错过bash历史的人: 在已经打开的git bash中,尝试启动另一个bash -如果env vars配置正确,应该会加载您的配置文件

如果这是你的情况,你可以通过在启动时添加以下命令行来自动化它:

C:\progra~1\git\usr\bin\bash.exe --login -l -i -c /c/progra~1/git/usr/bin/bash.exe

将profiles参数更改为"commandline": "%PROGRAMFILES%\\Git\\bin\\bash.exe -l -i"

这对我来说是可行的,并且允许运行.bash_profile别名自动完成脚本。

如果你想显示一个图标,并使用黑色主题。这意味着上面提供的图标看起来不太好。然后你可以在这里找到这个图标

C:\Program Files\Git\mingw64\share\git\ git-for-windows我复制到。

%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState

并将其命名为git-bash_32px。

用CTRL + SHIFT +滚动控制不透明度。

        {
            "acrylicOpacity" : 0.75,
            "closeOnExit" : true,
            "colorScheme" : "Campbell",
            "commandline" : "\"%PROGRAMFILES%\\git\\usr\\bin\\bash.exe\" -i -l",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Consolas",
            "fontSize" : 10,
            "guid" : "{73225108-7633-47ae-80c1-5d00111ef646}",
            "historySize" : 9001,
            "icon" : "ms-appdata:///roaming/git-bash_32px.ico",
            "name" : "Bash",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "startingDirectory" : "%USERPROFILE%",
            "useAcrylic" : true
        },

我是这样做的:

添加“%programfiles%\Git\Bin”到你的路径 在档案上。将需要的命令行设置为"commandline": "sh——cd-to-home" 重新启动Windows终端

这对我很管用。