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

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

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


当前回答

概述

用Ctrl+打开设置, 你需要将下面的一个配置文件选项(取决于你安装的git版本)追加到设置的“list”:部分。json文件:

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{00000000-0000-0000-ba54-000000000001}",

    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles
        },
        "list":
        [
            <put one of the configuration below right here>
        ]
    }
}

配置文件选项

取消注释命令行和图标的正确路径:

Git for Windows在%PROGRAMFILES% Git for Windows在%USERPROFILE% 如果你用勺子

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    "commandline": "%PROGRAMFILES%/Git/usr/bin/bash.exe -i -l",
    // "commandline": "%USERPROFILE%/AppData/Local/Programs/Git/bin/bash.exe -l -i",
    // "commandline": "%USERPROFILE%/scoop/apps/git/current/usr/bin/bash.exe -l -i",
    "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
    // "icon": "%USERPROFILE%/AppData/Local/Programs/Git/mingw64/share/git/git-for-windows.ico",
    // "icon": "%USERPROFILE%/scoop/apps/git/current/usr/share/git/git-for-windows.ico",
    "name" : "Bash",
    "startingDirectory" : "%USERPROFILE%"
},

您还可以添加其他选项,如:

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    // ...
    "acrylicOpacity" : 0.75,
    "closeOnExit" : true,
    "colorScheme" : "Campbell",
    "cursorColor" : "#FFFFFF",
    "cursorShape" : "bar",
    "fontFace" : "Consolas",
    "fontSize" : 10,
    "historySize" : 9001,
    "padding" : "0, 0, 0, 0",
    "snapOnInput" : true,
    "useAcrylic" : true
}

笔记

从https://github.com/microsoft/terminal/pull/2475开始创建自己的guid,这将不再生成。 guid可以在globals > defaultProfile中使用,所以你可以按下CtrlShiftT 或者启动一个Windows终端,它将默认启动bash

"defaultProfile" : "{00000000-0000-0000-ba54-000000000001}",

-l -i以确保加载.bash_profile 使用环境变量,这样它们就可以正确地映射到不同的系统。 目标git/bin/bash.exe,以避免产生额外的进程,根据进程资源管理器,与使用bin/bash或git-bash相比,每个进程节省约10MB

我的配置在https://gist.github.com/trajano/24f4edccd9a997fad8b4de29ea252cc8中使用Scoop

其他回答

概述

用Ctrl+打开设置, 你需要将下面的一个配置文件选项(取决于你安装的git版本)追加到设置的“list”:部分。json文件:

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{00000000-0000-0000-ba54-000000000001}",

    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles
        },
        "list":
        [
            <put one of the configuration below right here>
        ]
    }
}

配置文件选项

取消注释命令行和图标的正确路径:

Git for Windows在%PROGRAMFILES% Git for Windows在%USERPROFILE% 如果你用勺子

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    "commandline": "%PROGRAMFILES%/Git/usr/bin/bash.exe -i -l",
    // "commandline": "%USERPROFILE%/AppData/Local/Programs/Git/bin/bash.exe -l -i",
    // "commandline": "%USERPROFILE%/scoop/apps/git/current/usr/bin/bash.exe -l -i",
    "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
    // "icon": "%USERPROFILE%/AppData/Local/Programs/Git/mingw64/share/git/git-for-windows.ico",
    // "icon": "%USERPROFILE%/scoop/apps/git/current/usr/share/git/git-for-windows.ico",
    "name" : "Bash",
    "startingDirectory" : "%USERPROFILE%"
},

您还可以添加其他选项,如:

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    // ...
    "acrylicOpacity" : 0.75,
    "closeOnExit" : true,
    "colorScheme" : "Campbell",
    "cursorColor" : "#FFFFFF",
    "cursorShape" : "bar",
    "fontFace" : "Consolas",
    "fontSize" : 10,
    "historySize" : 9001,
    "padding" : "0, 0, 0, 0",
    "snapOnInput" : true,
    "useAcrylic" : true
}

笔记

从https://github.com/microsoft/terminal/pull/2475开始创建自己的guid,这将不再生成。 guid可以在globals > defaultProfile中使用,所以你可以按下CtrlShiftT 或者启动一个Windows终端,它将默认启动bash

"defaultProfile" : "{00000000-0000-0000-ba54-000000000001}",

-l -i以确保加载.bash_profile 使用环境变量,这样它们就可以正确地映射到不同的系统。 目标git/bin/bash.exe,以避免产生额外的进程,根据进程资源管理器,与使用bin/bash或git-bash相比,每个进程节省约10MB

我的配置在https://gist.github.com/trajano/24f4edccd9a997fad8b4de29ea252cc8中使用Scoop

将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
        },

这就是我如何在profiles json表中添加我的,

{
    "guid": "{00000000-0000-0000-ba54-000000000002}",
    "name": "Git",
    "commandline": "C:/Program Files/Git/bin/bash.exe --login",
    "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
    "startingDirectory": "%USERPROFILE%",
    "hidden": false
}

我是这样做的:

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

这对我很管用。