我试图添加一个新的终端(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”

其他回答

另一个需要注意的项目-在settings.json中 我发现如果你不使用 "commandline": "C:/Program Files/Git/bin/bash.exe"

取而代之的是: "commandline": "C:/Program Files/Git/ Git -bash.exe"

Git shell将在Windows终端之外的一个独立窗口中打开,而不是在一个选项卡中打开——这不是理想的行为。 此外,Windows终端中打开的选项卡也需要手动关闭,因为它将显示退出的进程信息-[退出的进程的代码为3221225786]等。

可能会让人头疼

对于那些可能错过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别名自动完成脚本。

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

步骤

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.

这是完整的答案(GitBash +配色方案+图标+上下文菜单)

设置默认配置文件:

"globals": 
{
    "defaultProfile" : "{00000000-0000-0000-0000-000000000001}",
    ...

添加giitbash配置文件

"profiles": [
    {
        "guid": "{00000000-0000-0000-0000-000000000001}",
        "acrylicOpacity": 0.75,
        "closeOnExit": true,
        "colorScheme": "GitBash",
        "commandline": "\"%PROGRAMFILES%\\Git\\usr\\bin\\bash.exe\" --login -i",
        "cursorColor": "#FFFFFF",
        "cursorShape": "bar",
        "fontFace": "Consolas",
        "fontSize": 10,
        "historySize": 9001,
        "icon": "%PROGRAMFILES%\\Git\\mingw64\\share\\git\\git-for-windows.ico",
        "name": "GitBash",
        "padding": "0, 0, 0, 0",
        "snapOnInput": true,
        "startingDirectory": "%USERPROFILE%",
        "useAcrylic": false
    }
]

添加giitbash配色方案

  "schemes": [
      {
          "background": "#000000",
          "black": "#0C0C0C",
          "blue": "#6060ff",
          "brightBlack": "#767676",
          "brightBlue": "#3B78FF",
          "brightCyan": "#61D6D6",
          "brightGreen": "#16C60C",
          "brightPurple": "#B4009E",
          "brightRed": "#E74856",
          "brightWhite": "#F2F2F2",
          "brightYellow": "#F9F1A5",
          "cyan": "#3A96DD",
          "foreground": "#bfbfbf",
          "green": "#00a400",
          "name": "GitBash",
          "purple": "#bf00bf",
          "red": "#bf0000",
          "white": "#ffffff",
          "yellow": "#bfbf00",
          "grey": "#bfbfbf"
      }
  ]

添加右键上下文菜单“Windows Terminal Here”

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows terminal here"
"Icon"="C:\\Users\\{YOUR_WINDOWS_USERNAME}\\AppData\\Local\\Microsoft\\WindowsApps\\{YOUR_ICONS_FOLDER}\\icon.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="\"C:\\Users\\{YOUR_WINDOWS_USERNAME}\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\""

将{YOUR_WINDOWS_USERNAME}替换为您的Windows用户名。 创建一个图标文件夹,把图标放在那里,用你的图标文件夹替换{YOUR_ICONS_FOLDER}。 将其保存在.reg文件中并运行。