SteveHawk's Blog

Windows Terminal 配置



简介

Windows Terminal 可以说是现在 Windows 平台最香的 Terminal 应用了。巨硬官方出品,开源,颜值在线,足够流畅,没有编码/字体问题,多标签支持,emoji 支持,可以说找不到第二个这么牛逼的了。

目前 Windows Terminal 在 Preview v0.7 版本。从 7 月份的第一个公开预览版到现在 12 月,快半年时间的打磨,已经没有太多影响体验的大 Bug 了。经过一阵的使用,我毅然抛弃了包括 cmd,PowerShell,Powershell Core,Linux Bash,Git Bash,Cmder 在内的一切 Terminal,Windows Terminal 大法好。下面记录一下配置过程。

安装

微软商店搜索 Windows Terminal (preview) 安装即可。

WT 配置

一切配置以 官方文档 为准。

Json 配置文件的编辑说明可以看 这里这里

在 WT 的菜单里点击 Settings 就可以打开 Json 配置文件。按住 alt 键点击 Settings 则可以打开默认配置文件,可以用于参考。参考默认配置后,我把我的配置设置成如下:

 1
 2// To view the default settings, hold "alt" while clicking on the "Settings" button.
 3// For documentation on these settings, see: https://aka.ms/terminal-documentation
 4
 5{
 6    "$schema": "https://aka.ms/terminal-profiles-schema",
 7
 8    "defaultProfile": "{2c4de342-38b7-51cf-b940-2309a097f518}",
 9    "initialCols" : 100,
10    "initialRows" : 30,
11
12    "profiles":
13    [
14        {
15            "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
16            "hidden": false,
17            "name": "Ubuntu",
18            "source": "Windows.Terminal.Wsl",
19            // "startingDirectory": "//wsl$/Ubuntu/home/steve",
20            "startingDirectory": ".",
21            "closeOnExit": true,
22            "colorScheme": "One Half Dark",
23            "cursorColor": "#FFFFFF",
24            "cursorShape": "bar",
25            "fontFace": "Delugia Nerd Font",
26            // Cascadia Code PL
27            // Delugia Nerd Font
28            "fontSize": 12,
29            "historySize": 9001,
30            "padding": "8, 8, 8, 8",
31            "snapOnInput": true,
32            "useAcrylic": true,
33            "acrylicOpacity": 0.8
34        },
35        {
36            "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
37            "name": "Powershell Core 6",
38            "commandline": "pwsh.exe",
39            "hidden": false,
40            // "startingDirectory": "%USERPROFILE%",
41            "startingDirectory": ".",
42            "closeOnExit": true,
43            "colorScheme": "One Half Dark",
44            "cursorColor": "#FFFFFF",
45            "cursorShape": "bar",
46            "fontFace": "Delugia Nerd Font",
47            "fontSize": 12,
48            "historySize": 9001,
49            "icon": "ms-appx:///ProfileIcons/{574e775e-4f2a-5b96-ac1e-a2962a402336}.png",
50            "padding": "8, 8, 8, 8",
51            "snapOnInput": true,
52            "useAcrylic": true,
53            "acrylicOpacity": 0.8
54        },
55        {
56            // Make changes here to the powershell.exe profile
57            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
58            "name": "Windows PowerShell",
59            "commandline": "powershell.exe",
60            "hidden": false,
61            "startingDirectory": ".",
62            "colorScheme": "One Half Dark",
63            "fontFace": "Delugia Nerd Font",
64            "useAcrylic": true,
65            "acrylicOpacity": 0.8
66        },
67        {
68            // Make changes here to the cmd.exe profile
69            "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
70            "name": "cmd",
71            "commandline": "cmd.exe",
72            "hidden": false,
73            "startingDirectory": ".",
74            "colorScheme": "One Half Dark",
75            "fontFace": "Delugia Nerd Font",
76            "useAcrylic": true,
77            "acrylicOpacity": 0.8
78        },
79        {
80            "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
81            "hidden": true,
82            "name": "Azure Cloud Shell",
83            "source": "Windows.Terminal.Azure"
84        }
85    ],
86
87    // Add custom color schemes to this array
88    "schemes": [],
89
90    // Add any keybinding overrides to this array.
91    // To unbind a default keybinding, set the command to "unbound"
92    "keybindings": []
93}

其中主要调整的几个点:

  1. 添加了 Powershell Core 6,并调整了各个 Shell 的顺序,优先打开 WSL。
  2. 把启动路径改成了 .,便于之后使用右键菜单“在此处打开”。(startingDirectory
  3. 颜色主题改成了自带的 One Half Dark。(colorScheme
  4. 字体改成了 Delugia Nerd Font。这是一个打包了 Nerd FontsCascadia Code 的非官方版本。如果你只需要 Powerline 相关的字体,那也可以选择官方的 Cascadia Code PL 字体。(fontFace
  5. 启用了毛玻璃效果。(useAcrylicacrylicOpacity
  6. 调整了初始的窗口大小设置。(initialColsinitialRows

主题

调整完上述 WT 设置后,WT 就已经足够好看了。下面我们让 Powershell 和 fish 在 WT 里更好看一点。利用 oh-my-poshoh-my-fish 这两个项目,分别给 Powershell 和 fish 加上 Powerline 和 Git 状态显示。

oh-my-posh

按照文档安装配置即可。

在 Powershell 中键入以下命令安装:

1Install-Module posh-git -Scope CurrentUser
2Install-Module oh-my-posh -Scope CurrentUser

Powershell Core 用户需要额外安装 [PSReadLine](Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck):

1Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck

输入 code $PROFILE 用 vscode 打开配置文件(或者用其他任何编辑器),在最后加入:

1Import-Module posh-git
2Import-Module oh-my-posh
3Set-Theme Agnoster
4$DefaultUser = '<YOUR-USERNAME-HERE>'

重启窗口即可生效。这样就把主题设置为了 Agnoster,当然也可以选择其他你喜欢的主题。另外设置了默认用户名,这样在默认用户下可以隐藏开头的 用户名@机器名 提示字符串。

oh-my-fish

按照文档安装配置即可。

直接在命令行输入以下一行即可安装:

1curl -L https://get.oh-my.fish | fish

安装完毕后,就可以安装设置自定义主题了。输入以下命令安装并应用 Agnoster 主题:

1omf install agnoster
2omf theme agnoster

当然你也可以使用其他你喜欢的主题

至此,整个美化就完成啦!

添加到右键菜单

最后,我们想要在右键菜单中添加 在此处打开 Windows Terminal 或者 Open WT here 的选项。

可以直接参考这篇把 Linux Bash 添加到右键菜单的文章:How to launch Bash shell from right-click context menu on Windows 10

唯一的不同就是里面的描述文字需要更改成 Windows Terminal / WT,启动指令需要改成 C:\Users\<YOUR-USERNAME-HERE>\AppData\Local\Microsoft\WindowsApps\wt.exe。另外,图标也需要改成 WT 的图标,可以从这里下载。

因此流程为:

  1. 到注册表编辑器里找到 HKEY_CLASSES_ROOT\Directory\Background\shell 项。
  2. 在该项下新建一个项,命名 WindowsTerminal
  3. 点击新建的这项,将默认值修改为 Open WT here
  4. 在该项下新建一个字符串值,名称为 Icon,值为图标路径。(该项操作可选)
  5. WindowsTerminal 项下再新建一项,命名为 command
  6. 将这项的默认值修改为启动 WT 的路径,一般为 C:\Users\<YOUR-USERNAME-HERE>\AppData\Local\Microsoft\WindowsApps\wt.exe

操作完成,在文件夹里右击就会出现 Open WT here 的选项啦。


#tech notes
本文总字数 1841
本文阅读量
本站访客量

↪ reply by email