Windows Terminal 在 PC 上是比较好看的终端,在安装 Powershell v7 或者 Windows Subsystem Linux 之后都会自动在 Windows Terminal 的配置文件中自动生成对应的设置,从而可以在 Windows Terminal 中使用。
但是,我在安装 Anaconda 之后发现 Windows Terminal 并没有为其自动生成设置,所以为了用上更好看的界面,需要对 Windows Terminal 的配置文件进行一定的修改。
首先,得知道 Anaconda 的终端要怎么运行起来:
我安装的 Anaconda 版本是 Anaconda3-2020.07 64 位的,自带两个终端:Anaconda Prompt (anaconda3) 和 Anaconda Powershell Prompt (anaconda3),分别对应 CMD 和 Powershell。
值得注意的是它们并非独立的可执行文件 .exe,而是快捷方式,查看它们的属性就知道只是运行了一段命令来激活 conda 环境而已。
在快捷方式的目标一栏就可以看到它们运行的命令分别是:
%windir%\System32\cmd.exe "/K" C:\Users\qq875\anaconda3\Scripts\activate.bat C:\Users\qq875\anaconda3
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\Users\qq875\anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\qq875\anaconda3' "
知道了终端运行的命令之后,我们来看 Windows Terminal 的配置文件 settings.json:
......
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
......
"profiles":
{
......
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false
},
......
可以看到 profiles 中的 list 下面就是放各个终端设置的地方,我们需要为 Anaconda 的两个终端添加设置
我们依次将 name 和 commandline 设置好,后者需要注意语法,例如双引号 " 需要用 \ 防止误认,以及路径中的 \ 需要用 // 替代。
需要注意的是最前面还需要一个 guid,可以用来将其复制到上方的 defaultProfile 中,则对应的终端就是 Windows Terminal 默认开启的终端了。GUID 我们可以用 Powershell 来生成,命令是:
[guid]::NewGuid()
最后为了美观,我们可以添加一个 icon。
我把最终的配置文件贴在下面:
......
"defaultProfile": "{8399643c-5298-4c9a-af1d-4ce616834506}",
......
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false
},
{
// Make changes here to the powershell.exe profile.
"guid": "{4e40e6a9-1f76-4fee-a760-9cbdad60d6d7}",
"name": "Anaconda Powershell Prompt (anaconda3)",
"commandline": "powershell.exe -ExecutionPolicy ByPass -NoExit -Command \"& \"C://Users//qq875//anaconda3//shell//condabin//conda-hook.ps1\" ; conda activate \"C://Users//qq875//anaconda3\" \"",
"icon": "C://Users//qq875//anaconda3//Menu//Iconleak-Atrous-PSConsole.ico",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{8399643c-5298-4c9a-af1d-4ce616834506}",
"name": "Anaconda Prompt (anaconda3)",
"commandline": "cmd.exe \"/K\" C://Users//qq875//anaconda3//Scripts//activate.bat C://Users//qq875//anaconda3",
"icon" : "C://Users//qq875//anaconda3//Menu//Iconleak-Atrous-PSConsole.ico",
"hidden": false
},
]
},
......