终端效果

通过 Powerline 来自定义 PowerShell,以提供Git状态提示符,再对 Windows Terminal 美化,得到一个优秀的终端体验

这里先放出微软的官方教程:

https://docs.microsoft.com/zh-cn/windows/terminal/tutorials/powerline-setup#set-up-powerline-in-wsl-ubuntu

但是微软给出的文档有坑,到本文编写的时候文档还没有进行修改,不妨按照我的步骤来设置

安装OhMyPosh的字体

如果不安装字体,最后终端可能会出现乱码

这里我们需要安装 Meslo LGM NF 字体,这是 Oh my Posh 官方推荐使用的字体,使用微软推荐的Cascadia Code PLCascadia Mono PL 会出现图标不显示的问题

Github链接:

https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip

网络不好的可以通过Github的镜像站来下载

https://hub.fastgit.org/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip

下载后解压,进入ttf文件夹,选中下图的ttf文件,分别是常规、粗体、斜体、粗斜体,右键进行安装

安装字体

安装完后可以在字体设置中预览

预览字体

在PowerShell中安装Posh-Git和Oh-My-Posh

在执行这一步前,先确保你安装了git

在这一步中,我们会安装 Posh-Git 和 Oh-My-Posh:

在PoweShell窗口中,用 Terminal 打开 PowerShell 也行,执行以下命令

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

如果想为全部用户安装,使用管理员打开 Terminal 或 PowerShell 执行以下命令

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

如果出现不受信任的存储库,就选择A

如果需要更新这两个工具,执行以下命令

1
2
Update-Module -Name posh-git
Update-Module -Name oh-my-posh

要注意的是,全局安装的模块需要管理员权限才能进行更新

更新 posh-git

更新 oh-my-posh

更新完之后我们要卸载旧版本的模块

先获取模块的版本号,需要记住旧版本的版本号

1
Get-Module -ListAvailable

获取模块的版本号

卸载旧版本的模块

1
2
Uninstall-Module -Name "posh-git" -RequiredVersion "0.7.3"
Uninstall-Module -Name "oh-my-posh" -RequiredVersion "3.106.7"

最后再确认一下是否卸载成功

确认是否卸载成功

自定义PowerShell 提示符

现在当前PowerShell窗口导入posh-git和oh-my-posh

1
2
Import-Module posh-git
Import-Module oh-my-posh

如果出现无法加载的问题,可以更改 PowerShell 的执行策略解决:Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

无法加载

然后我们输入以下命令来预览效果

1
Get-PoshThemes

预览效果

选择你喜欢的主题,记住他的名称,我这里选择honukai主题

输入这个命令

1
notepad $PROFILE

添加以下内容,在每次打开PowerShell的时候,就会执行里面的命令

1
2
3
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme honukai

保存并退出,重新打开PowerShell,你就会看到你选择的主题了

这里和微软官方的文档不同,因为oh-my-posh的新版本使用go来重写了,指令发生了变化,所以旧的命令是无效的

WindowsTerminal美化

打开Terminal,点击 Ctrl + , 打开配置文件

这里放出我的配置文件,你也可以自己设置,但是 “fontFace” 这一项一定要设置成 MesloLGM NF 字体,否则会乱码

1
"fontFace": "MesloLGM NF",

配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// This file was initially generated by Windows Terminal 1.0.1401.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",

"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings

// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,

// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,

// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles": {
"defaults": {
// Put settings here that you want to apply to all profiles.
},
"list": [
{
// Make changes here to the powershell.exe profile.
"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg",
"backgroundImageOpacity": 0.6,
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"colorScheme": "AdventureTime",
"useAcrylic": false,
"closeOnExit": true,
"acrylicOpacity": 0.25,
"cursorColor": "#FFFFFF",
"fontFace": "MesloLGM NF",
"tabTitle": "Powershell",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg",
"backgroundImageOpacity": 0.6,
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"colorScheme": "AdventureTime",
"useAcrylic": false,
"closeOnExit": true,
"acrylicOpacity": 0.25,
"cursorColor": "#FFFFFF",
"fontFace": "MesloLGM NF",
"hidden": false
},
{
"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg",
"backgroundImageOpacity": 0.6,
"guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
"hidden": false,
"name": "Ubuntu-20.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu-20.04/home/hominsu",
"colorScheme": "AdventureTime",
"useAcrylic": false,
"closeOnExit": true,
"acrylicOpacity": 0.25,
"cursorColor": "#FFFFFF",
"fontFace": "MesloLGM NF"
},
{
"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg",
"backgroundImageOpacity": 0.6,
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu-18.04/home/hominsu",
"colorScheme": "AdventureTime",
"useAcrylic": false,
"closeOnExit": true,
"acrylicOpacity": 0.25,
"cursorColor": "#FFFFFF",
"fontFace": "MesloLGM NF"
},
{
"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg",
"backgroundImageOpacity": 0.6,
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"colorScheme": "AdventureTime",
"useAcrylic": false,
"closeOnExit": true,
"acrylicOpacity": 0.25,
"cursorColor": "#FFFFFF",
"fontFace": "MesloLGM NF",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
}
]
},

// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [
{
"name": "AdventureTime",
"black": "#050404",
"red": "#bd0013",
"green": "#4ab118",
"yellow": "#e7741e",
"blue": "#0f4ac6",
"purple": "#665993",
"cyan": "#70a598",
"white": "#f8dcc0",
"brightBlack": "#4e7cbf",
"brightRed": "#fc5f5a",
"brightGreen": "#9eff6e",
"brightYellow": "#efc11a",
"brightBlue": "#1997c6",
"brightPurple": "#9b5953",
"brightCyan": "#c8faf4",
"brightWhite": "#f6f5fb",
"background": "#000000",
"foreground": "#f8dcc0"
}
],

// Add custom keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings
"keybindings": [
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{
"command": {
"action": "copy",
"singleLine": false
},
"keys": "ctrl+c"
},
{
"command": "paste",
"keys": "ctrl+v"
},

// Press Ctrl+Shift+F to open the search box
{
"command": "find",
"keys": "ctrl+shift+f"
},

// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{
"command": {
"action": "splitPane",
"split": "auto",
"splitMode": "duplicate"
},
"keys": "alt+shift+d"
}
]
}

这是文件中的图片,这张图片是某天微软丢到我的邮箱里的,很好看,就一直用了下去

这里放上链接

https://image.hauhau.cn/WIP-6th-anniversary-wallpaper-dark.jpg

WIP-6th-anniversary-wallpaper-dark

https://image.hauhau.cn/WIP-6th-anniversary-wallpaper-light.jpg

WIP-6th-anniversary-wallpaper-light

到此,我们的美化就基本完成了