我试图添加一个新的终端(Git Bash)到新的Windows终端。然而,我不能让它工作。
我尝试将profiles数组中的命令行属性更改为git-bash.exe,但没有运气。
有人知道怎么让它工作吗?
我试图添加一个新的终端(Git Bash)到新的Windows终端。然而,我不能让它工作。
我尝试将profiles数组中的命令行属性更改为git-bash.exe,但没有运气。
有人知道怎么让它工作吗?
将profiles参数更改为"commandline": "%PROGRAMFILES%\\Git\\bin\\bash.exe -l -i"
这对我来说是可行的,并且允许运行.bash_profile别名自动完成脚本。
我是这样做的:
添加“%programfiles%\Git\Bin”到你的路径 在档案上。将需要的命令行设置为"commandline": "sh——cd-to-home" 重新启动Windows终端
这对我很管用。
添加“%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”
概述
用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
有以下事情要做。
确保git命令在命令提示符中成功运行。
这意味着您需要在安装git时将git添加到path或稍后将其添加到系统环境中。
更新文件配置文件。通过按Ctrl+打开设置,在Windows终端中,单击侧边栏中的打开json文件,并在word 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
}
图标获取路径:git-bash_32px.ico
您可以在此位置添加Tab图标:
%LOCALAPPDATA%\packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState
在这个文件夹中放入32x32的PNG/图标,然后在配置文件中。你可以引用以ms-appdata://开头的图像资源。
注意,请确保指南是正确的,它匹配相应的正确配置。
测试git bash在Windows终端中工作。
最终结果如下:
如果你想显示一个图标,并使用黑色主题。这意味着上面提供的图标看起来不太好。然后你可以在这里找到这个图标
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
},
这是完整的答案(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文件中并运行。
另一个需要注意的项目-在settings.json中 我发现如果你不使用 "commandline": "C:/Program Files/Git/bin/bash.exe"
取而代之的是: "commandline": "C:/Program Files/Git/ Git -bash.exe"
Git shell将在Windows终端之外的一个独立窗口中打开,而不是在一个选项卡中打开——这不是理想的行为。 此外,Windows终端中打开的选项卡也需要手动关闭,因为它将显示退出的进程信息-[退出的进程的代码为3221225786]等。
可能会让人头疼
因为大多数答案要么显示大量不相关的配置,要么不显示配置,所以我创建了自己的答案,试图更集中。它主要是基于配置文件设置参考和阿基米德特拉哈诺的答案。
步骤
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.
这就是我如何在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
}
新版本的windows终端可以通过其GUI进行配置。
Setting -> Add new
Under "command line" add the path -> path/to/Git/bin/bash.exe
现在是2021年9月,谢天谢地,最新的Windows Git安装安装程序(我使用的是2.33.0.2)已经为我们覆盖了这个选项,为了我们的懒惰(当然也为了方便!)
请在安装Git之前先安装Windows终端,虽然我没有尝试过相反的方法,但最好遵循合理的顺序。如果安装顺序不是这样,请让我知道更新这个答案。
您可能会在安装阶段Select Components的底部发现这个少量复选框,只需勾选那里的复选框,就可以开始了。
设置。json文件将自动添加到Git Bash配置文件中,并带有正确的Git Bash图标。我生成的Git Bash配置文件非常标准和简洁。
{
"guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
"hidden": false,
"name": "Git Bash",
"source": "Git"
}
如果Windows终端正在运行,请关闭并再次启动,以便Git Bash选项可见。
如果有人正在寻找一个基于ui的解决方案。下面就是:
进入终端设置。 在右下角,寻找“添加新配置文件”选项。 终端设置的截图。 选择“新建空配置文件” 现在用关于bash的信息完成字段。如果你的安装位置是默认的,你可以使用这些:
名称:Git-Bash 命令行:C:\Program Files\Git\bin\bash.exe 启动目录:[保留默认值] 图标:C:\Program Files\Git\mingw64\share\git\ git-for-windows.ico 标签标题:Git-Bash 终端设置完成 如果需要的话,您还可以浏览正确的文件。
点击保存按钮。
最终结果
最终结果。Bash终端
对于那些可能错过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
搞Linux的,抱歉我来晚了;我只是第一次安装git-bash,并研究它的命令应该在Windows终端中。
据我所知
Cygwin is not Windows, but it provides a POSIX translation layer (cygwin*.dll) so that all those non-Windows executables can run. Even when a new computer program is compiled and built with cygwin, it still turns out a non-Windows executable and it still needs cygwin*.dll to run. MSYS2 is mostly Windows with only a few tools that are probably difficult to port remaining non-Windows and requiring a POSIX translation layer to run (msys*.dll); but, most programs are actually Windows native executables. Even when a new computer program is compiled and built, it is my understanding that turns out a Windows native *.exe.
但我仍然不知道这些MSYSTEM*和MINGW*环境变量是否设置有多重要,当我要使用MINGW编译器时,无论如何。
我确实注意到,在整个线程中,两个命令行都不断出现,即./bin/bash和./usr/bin/bash;所以,我把它们发射出去,比较它们的环境……结果可能会大不相同。
要知道,在启动下面的任何shell之前,我已经有C:\Git\mingw64\bin和C:\Git\usr\bin作为系统变量PATH的一部分;我这样做是因为我希望能够直接从CMD使用bash命令。但我不认为这对下面的结果有任何影响。
c:\Git\bin\bash.exe --login c:\Git\usr\bin\bash.exe --login
Environment Variable c:\Git\bin\bash.exe c:\Git\usr\bin\bash.exe
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EXEPATH c:\git\bin c:\git\bin n n
HOSTNAME n MDXXXXXX n MDXXXXXX
MINGW_CHOST n x86_64-w64-mingw32 n n
MINGW_PACKAGE_PREFIX n mingw-w64-x86_64 n n
MINGW_PREFIX n /mingw64 n n
MSYSTEM_CARCH n x86_64 n x86_64
MSYSTEM_CHOST n x86_64-w64-mingw32 n x86_64-pc-msys
MSYSTEM_PREFIX n /mingw64 n /usr
MSYSTEM MINGW64 MINGW64 n MSYS
PLINK_PROTOCOL ssh ssh n n
SHELL n /usr/bin/bash n /usr/bin/bash
TMPDIR n /tmp n /tmp
ORIGINAL_PATH n y n y
ORIGINAL_TEMP n y n y
ORIGINAL_TMP n y n y
PATH /mingw64/bin:/usr/bin:$HOME/bin:$PATH
PATH $HOME/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:$HOME/bin:$PATH
PATh $PATH
PATH $HOME/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:$PATH
因此,在我看来,更正确的做法是使用。/bin/bash——login;但此时此刻,我不确定会有什么不同,比如说,当真正使用MINGW64/GCC编译一个全新的程序时;让我们拭目以待。
据我所知,我目前的windows终端版本为1.15.2874.0,你可以通过简单的手动单击来配置它。 前提条件是
安装git bash客户端。 Windows终端版本1.15.2874.0及以上。
然后按照以下步骤完成设置。
Open windows terminal and find "Settings" in the drop-down list in the top right corner of the menu bar (or use the shortcut ctrl+,); Click on "Add new profile" at the bottom of the left hand column, then the settings template screen will pop up automatically. interactive mouse click you want to set the "name", "executable path command line", "startup directory", "icon" value. For example, I set mine to "gitBash", "C:\Program Files\Git\bin\bash.exe", "%USERPROFILE%", and "%USERPROFILE%" in order of customisation. "C:\Program Files\Git\mingw64\share\git\git-for-windows.ico". save.
以下截图仅供参考。