Men*_*ndy 41 git-bash windows-terminal
我正在尝试将新终端(Git Bash)添加到新的Windows终端,但是无法正常工作。
我尝试将数组中的commandline属性更改为profiles,git-bash.exe但没有运气。
有谁知道如何使它起作用?
提前致谢。
Tha*_*uoc 109
现在是2021 年 9 月,幸运的是,为了我们的懒惰(当然也是为了方便!),最新的Windows 版 Git 安装程序(我使用的是 2.33.0.2)已经为我们提供了这个选项。
请先安装 Windows 终端,然后再安装 Git,虽然我没有尝试过相反的方式,但最好遵循合理的顺序。如果安装顺序不正确,请告诉我更新此答案。
您可能会在安装阶段“选择组件”底部找到这个复选框,只需勾选那里的框即可开始。

该settings.json文件将自动添加到 Git Bash 配置文件中,并带有正确的 Git Bash 图标。我生成的 Git Bash 配置文件非常标准且最小。
{
"guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
"hidden": false,
"name": "Git Bash",
"source": "Git"
}
Run Code Online (Sandbox Code Playgroud)
如果 Windows 终端正在运行,请关闭并再次启动以使 Git Bash 选项可见。
Arc*_*ano 69
{
"guid": "{00000000-0000-0000-ba54-000000000002}",
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "\"%PROGRAMFILES%\\git\\usr\\bin\\bash.exe\" -i -l",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "Bash",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
Run Code Online (Sandbox Code Playgroud)
如果您使用独家新闻
{
"guid": "{00000000-0000-0000-ba54-000000000001}",
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "\"%UserProfile%\\scoop\\apps\\git\\current\\usr\\bin\\bash.exe\" -i -l",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 10,
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "Bash",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
Run Code Online (Sandbox Code Playgroud)
guid,不再生成。guid可以在使用globals> defaultProfile,所以你可以按你可以按CtrlShiftT
或启动Windows终端,它会默认启动的bash"defaultProfile" : "{00000000-0000-0000-ba54-000000000001}",
Run Code Online (Sandbox Code Playgroud)
-i -l确保.bash_profile加载git\bin\bash.exe是避免产生其他进程,根据Process Explorer的统计,与使用bin / bash或git-bash相比,每个进程可节省约10MB我的配置在https://gist.github.com/trajano/24f4edccd9a997fad8b4de29ea252cc8中使用Scoop
Joj*_*GME 48
因为大多数答案要么显示很多不相关的配置,要么不显示配置,所以我创建了自己的答案,试图更加专注。它主要基于配置文件设置参考和Archimedes Trajano 的回答。
打开PowerShell并输入[guid]::NewGuid()以生成新的 GUID。我们将在步骤 3 中使用它。
> [guid]::NewGuid()
Guid
----
a3da8d92-2f3f-4e36-9714-98876b6cb480
Run Code Online (Sandbox Code Playgroud)
打开Windows 终端的设置。( CTRL+ ,)
将以下 JSON 对象添加到profiles.list. 替换guid为您在第 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%"
},
Run Code Online (Sandbox Code Playgroud)
当前存在一个问题,您无法使用箭头键(和其他一些键)。不过,它似乎适用于最新的预览版本。(问题#6859)
根据参考,"startingDirectory" : "%USERPROFILE%"不需要指定。但是,如果我不指定它,根据我最初启动终端的方式,起始目录会有所不同。
适用于所有终端的设置可以在 中指定profiles.defaults。
我建议"antialiasingMode": "cleartype"在profiles.defaults. 您必须删除"useAcrylic"(如果您按照其他一些答案的建议添加了它)才能使其工作。它提高了文本渲染的质量。但是,没有useAcrylic. 请参阅问题 #1298。
如果光标有问题,可以尝试另一种形状,例如"cursorShape": "filledBox"。有关详细信息,请参阅光标设置。
Bra*_*ung 23
以下是要做的事情。
git命令可以在CMD中成功运行这意味着您需要git在安装git时添加到path或稍后将其添加到系统环境中。
profile.json打开Settings,在单词中添加以下代码段profiles:
{
"tabTitle": "Git Bash",
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "C:/Program Files/Git/bin/bash.exe --login",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 12,
"guid" : "{14ad203f-52cc-4110-90d6-d96e0f41b64d}",
"historySize" : 9001,
"icon": "ms-appdata:///roaming/git-bash_32px.ico",
"name" : "Git Bash",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"useAcrylic" : true
}
Run Code Online (Sandbox Code Playgroud)
可以在这里获取图标: git-bash_32px.ico
您可以将Tab标签的图标添加到以下位置:
%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState
将32x32 PNG / icons放在此文件夹中,然后profile.json您可以使用以ms-appdata://开头的路径引用图像资源。
请注意,请确保Guid正确,并且与相应的正确配置匹配。
Windows Terminal小智 23
这就是我如何在配置文件 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
}
Run Code Online (Sandbox Code Playgroud)
小智 20
如果有人正在寻找基于 UI 的解决方案。这里是:
转到终端的设置。
在右侧按钮侧,查找“添加新配置文件”选项。 终端设置的屏幕截图。
选择“新建空配置文件”
现在用有关您的 bash 的信息填写字段。如果您的安装位置是默认位置,您可以使用以下位置:
最后结果
小智 14
另一个需要注意的项目 - 在 settings.json 我发现如果你不使用“命令行”:“C:/Program Files/Git/bin/bash.exe”
而是使用: "commandline": "C:/Program Files/Git/git-bash.exe"
Git shell 将在 Windows 终端之外的独立窗口中打开,而不是在选项卡上 - 这不是所需的行为。此外,Windows Terminal 中打开的选项卡也需要手动关闭,因为它会显示进程退出信息 - [进程退出代码 3221225786] 等。
可能会让人头疼
Alt*_*tin 11
这是完整的答案(GitBash +配色方案+图标+上下文菜单)
1)设置默认配置文件:
"globals" :
{
"defaultProfile" : "{00000000-0000-0000-0000-000000000001}",
...
Run Code Online (Sandbox Code Playgroud)
2)添加GitBash配置文件
"profiles" :
[
{
"guid": "{00000000-0000-0000-0000-000000000001}",
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "GitBash",
"commandline" : "\"%PROGRAMFILES%\\Git\\usr\\bin\\bash.exe\" --login -i -l",
"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
},
Run Code Online (Sandbox Code Playgroud)
3)添加GitBash配色方案
"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"
},
Run Code Online (Sandbox Code Playgroud)
4)要添加右键单击上下文菜单“ 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\""
Run Code Online (Sandbox Code Playgroud)
小智 8
将配置文件参数更改为 "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
Run Code Online (Sandbox Code Playgroud)
并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
},
Run Code Online (Sandbox Code Playgroud)
小智 6
新版本的 windows 终端可以通过其 GUI 进行配置。
Setting -> Add new
Under "command line" add the path -> path/to/Git/bin/bash.exe
Run Code Online (Sandbox Code Playgroud)
我相信,从 2023 年 8 月发布的 Git For Windows2.42.0或更高版本开始,您现在可以重新运行安装程序并选中 的框(NEW!) Add a Git Bash Profile to Windows Terminal,如设置中的蓝色所示Git 2.42.0:
就是这样!
我首先在此处的说明中记录了这一点:有关安装适用于 Windows 的 Git 时选择的其他推荐设置,请参阅此处我的个人安装说明:安装适用于 Windows 的 Git。
如果echo ~Git Bash 中没有显示正确的 HOME 目录,请参阅此处的说明来修复它:更改Windows 安装的 Git Bash 中的 [Home] 目录的位置~。
如果您需要在 Windows 中使用gcc/g++或进行构建clang,请改用 MSYS2 终端。
请参阅我的 MSYS2 设置答案:从头开始安装和设置 MSYS2,包括将所有 7 个配置文件添加到 Windows 终端
现在,终端可以选择添加新配置文件,而无需修改 JSON 设置。
从下拉菜单中转到“设置”,如下所示。
在侧边栏的“个人资料”部分下,选择“添加新个人资料”。单击“+新的空个人资料”。将打开以下屏幕。
添加如下屏幕所示的 git bash 或任何其他 bash 的详细信息。
就这样!
| 归档时间: |
|
| 查看次数: |
9843 次 |
| 最近记录: |