1. 预先准备

1.1 美化PowerShell

在ArchLinux上用的是Oh-My-Zsh。为了符合习惯,使用类似的Posh-Git和Oh-My-Posh,在PowerShell中执行以下的命令进行安装:

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

打开 PowerShell 的配置文件:

1
notepad $PROFILE

添加以下内容,本人选择的主题是Agnoster,为了与Oh-My-Zsh的主题保持一致性。

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

特别注意字体,一定要使用支持Powerline的字体,否则会产生乱码。

1.2 PSReadLine的使用

PSReadLine是一个用于增强PowerShell命令行编辑体验的模块,其安装和使用说明请参考其开源项目主页。由于使用的复杂性,为了简单起见,只加入自动补全功能:

仍是在PowerShell的配置文件中输入,即可实现在zsh下的Menu补全。

1
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

2. 配置

2.1 Global Setting 配置

2.1.1 对所有的Profile进行设置

不搞花里胡哨的背景图片。所有Profile均采用同样的风格。

1
2
3
4
5
6
7
8
9
10
11
{
"profiles": {
"defaults": {
"fontFace": "MesloLG NF",
"fontSize": 14,
"colorScheme": "Dracula",
"acrylicOpacity": 0.8,
"useAcrylic": true
}
}
}

2.1.2 退出 Windows Terminal

1
{ "command": "closeWindow", "keys": "alt+shift+q" }

2.2 Color Schemes 配置

这个主题配置主题颜色的JSON文件来源为开源项 iTerm2-Color-Schemes。因为本人在VsCode采用的主题也是Dracula,为了保持一致性,Windows Terminal的配色主题也是采用Dracula。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{ "schemes": [{
"name": "Dracula",
"black": "#000000",
"red": "#ff5555",
"green": "#50fa7b",
"yellow": "#f1fa8c",
"blue": "#bd93f9",
"purple": "#ff79c6",
"cyan": "#8be9fd",
"white": "#bbbbbb",
"brightBlack": "#555555",
"brightRed": "#ff5555",
"brightGreen": "#50fa7b",
"brightYellow": "#f1fa8c",
"brightBlue": "#bd93f9",
"brightPurple": "#ff79c6",
"brightCyan": "#8be9fd",
"brightWhite": "#ffffff",
"background": "#1e1f29",
"foreground": "#f8f8f2"
}]
}

为了使所有的Profile能够使用这个配色主题,在Profile中的defaults添加如下信息:

1
2
3
4
5
{
"defaults": {
"colorScheme": "Dracula"
}
}

2.3 Key bindings

由于Linux系统使用ArchLinux i3,为了符合ArchLinux i3的习惯。此处的Modifier只会采用Alt,而且设置习惯将会根据i3的快捷键设置。

2.3.1 Tab 管理命令配置

用于创建新的tab,以及默认tab的打开:

1
2
3
4
5
6
7
8
9
10
[{ "command": "newTab", "keys": "alt+enter" },
{ "command": { "action": "newTab", "index": 0 }, "keys": "alt+shift+1" },
{ "command": { "action": "newTab", "index": 1 }, "keys": "alt+shift+2" },
{ "command": { "action": "newTab", "index": 2 }, "keys": "alt+shift+3" },
{ "command": { "action": "newTab", "index": 3 }, "keys": "alt+shift+4" },
{ "command": { "action": "newTab", "index": 4 }, "keys": "alt+shift+5" },
{ "command": { "action": "newTab", "index": 5 }, "keys": "alt+shift+6" },
{ "command": { "action": "newTab", "index": 6 }, "keys": "alt+shift+7" },
{ "command": { "action": "newTab", "index": 7 }, "keys": "alt+shift+8" },
{ "command": { "action": "newTab", "index": 8 }, "keys": "alt+shift+9" }]

用于创建一个当前tab的副本并打开:

1
{ "command": "duplicateTab", "keys": "alt+shift+d" }

用于关闭当前的tab:

1
{ "command": "closeTab", "keys": "alt+q" }

用于切换tab:

1
2
3
4
5
6
7
8
9
[{ "command": { "action": "switchToTab", "index": 0 }, "keys": "alt+1" },
{ "command": { "action": "switchToTab", "index": 1 }, "keys": "alt+2" },
{ "command": { "action": "switchToTab", "index": 2 }, "keys": "alt+3" },
{ "command": { "action": "switchToTab", "index": 3 }, "keys": "alt+4" },
{ "command": { "action": "switchToTab", "index": 4 }, "keys": "alt+5" },
{ "command": { "action": "switchToTab", "index": 5 }, "keys": "alt+6" },
{ "command": { "action": "switchToTab", "index": 6 }, "keys": "alt+7" },
{ "command": { "action": "switchToTab", "index": 7 }, "keys": "alt+8" },
{ "command": { "action": "switchToTab", "index": 8 }, "keys": "alt+9" }]

2.3.2 Pane 管理命令配置

关闭当前聚焦的pane。如果没有Pane,就会直接关闭掉当前的Tab。如果只有一个Tab打开,将会关闭窗口:

1
{ "command": "closePane", "keys": "alt+w" }

改变当前聚焦的pane的尺寸:

1
2
3
4
[{ "command": { "action": "resizePane", "direction": "down" }, "keys": "alt+shift+down" },
{ "command": { "action": "resizePane", "direction": "left" }, "keys": "alt+shift+left" },
{ "command": { "action": "resizePane", "direction": "right" }, "keys": "alt+shift+right" },
{ "command": { "action": "resizePane", "direction": "up" }, "keys": "alt+shift+up" }]

利用当前的profile划分pane:

1
2
[{ "command": { "action": "splitPane", "split": "horizontal"}, "keys": "alt+h" },
{ "command": { "action": "splitPane", "split": "vertical"}, "keys": "alt+v" }]

利用其他的profile进行分割。由于alt+index以及alt+shift+index均用于了Tab的管理,此处不得不采用Modifier ctrl

1
2
3
4
5
6
7
8
9
[{ "command": { "action": "splitPane", "split": "auto", "index": 0 }, "keys": "ctrl+alt+1" },
{ "command": { "action": "splitPane", "split": "auto", "index": 1 }, "keys": "ctrl+alt+2" },
{ "command": { "action": "splitPane", "split": "auto", "index": 2 }, "keys": "ctrl+alt+3" },
{ "command": { "action": "splitPane", "split": "auto", "index": 3 }, "keys": "ctrl+alt+4" },
{ "command": { "action": "splitPane", "split": "auto", "index": 4 }, "keys": "ctrl+alt+5" },
{ "command": { "action": "splitPane", "split": "auto", "index": 5 }, "keys": "ctrl+alt+6" },
{ "command": { "action": "splitPane", "split": "auto", "index": 6 }, "keys": "ctrl+alt+7" },
{ "command": { "action": "splitPane", "split": "auto", "index": 7 }, "keys": "ctrl+alt+8" },
{ "command": { "action": "splitPane", "split": "auto", "index": 8 }, "keys": "ctrl+alt+9" }]

2.3.3 字体大小重置

1
{ "command": "resetFontSize", "keys": "alt+r" }

3. 配置文件全部

此处给出所有的配置文件,供参考。

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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
{
//! Do not edit this
"$schema": "https://aka.ms/terminal-profiles-schema",

//! To set the default profile to PowerShell7
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",

//! To define the profiles
"profiles": {
//! Settings to apply to all profiles
"defaults": {
"fontFace": "MesloLGS NF",
"fontSize": 14, // 老年人了
"colorScheme": "Dracula",
"acrylicOpacity": 0.8,
"useAcrylic": true
},
//! Profile objects
"list": [
//! PowerShell 7
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"tabTitle": "PowerShell 7",
"hidden": false,
"name": "PowerShell",
"source": "Windows.Terminal.PowershellCore"

},
//! Windows PowerShell 5.1
{
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
//! Don't need at this time
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": true,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
//! CMD
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false,
"tabTitle": "cmd"
}


]
},

//! To define the Dracula theme
"schemes": [{
"name": "Dracula",
"black": "#000000",
"red": "#ff5555",
"green": "#50fa7b",
"yellow": "#f1fa8c",
"blue": "#bd93f9",
"purple": "#ff79c6",
"cyan": "#8be9fd",
"white": "#bbbbbb",
"brightBlack": "#555555",
"brightRed": "#ff5555",
"brightGreen": "#50fa7b",
"brightYellow": "#f1fa8c",
"brightBlue": "#bd93f9",
"brightPurple": "#ff79c6",
"brightCyan": "#8be9fd",
"brightWhite": "#ffffff",
"background": "#1e1f29",
"foreground": "#f8f8f2"
}

],

"keybindings": [{
"command": {
"action": "copy",
"singleLine": false
},
"keys": "ctrl+c"
},

{
"command": "paste",
"keys": "ctrl+v"
},

//! To open the search box
{
"command": "find",
"keys": "alt+f"
},

//! To exit the Windows Terminal
{
"command": "closeWindow",
"keys": "alt+shift+q"
},

//! To open the default tab
{
"command": "newTab",
"keys": "alt+enter"
},

//! To duplicate the current tab and open it
{
"command": "duplicateTab",
"keys": "alt+shift+d"
},

//* To open the tab by index
{
"command": {
"action": "newTab",
"index": 0
},
"keys": "alt+shift+1"
},
{
"command": {
"action": "newTab",
"index": 1
},
"keys": "alt+shift+2"
},
{
"command": {
"action": "newTab",
"index": 2
},
"keys": "alt+shift+3"
},
{
"command": {
"action": "newTab",
"index": 3
},
"keys": "alt+shift+4"
},
{
"command": {
"action": "newTab",
"index": 4
},
"keys": "alt+shift+5"
},
{
"command": {
"action": "newTab",
"index": 5
},
"keys": "alt+shift+6"
},
{
"command": {
"action": "newTab",
"index": 6
},
"keys": "alt+shift+7"
},
{
"command": {
"action": "newTab",
"index": 7
},
"keys": "alt+shift+8"
},
{
"command": {
"action": "newTab",
"index": 8
},
"keys": "alt+shift+9"
},
//* End

//* To switch to a tab by index
{
"command": {
"action": "switchToTab",
"index": 0
},
"keys": "alt+1"
},
{
"command": {
"action": "switchToTab",
"index": 1
},
"keys": "alt+2"
},
{
"command": {
"action": "switchToTab",
"index": 2
},
"keys": "alt+3"
},
{
"command": {
"action": "switchToTab",
"index": 3
},
"keys": "alt+4"
},
{
"command": {
"action": "switchToTab",
"index": 4
},
"keys": "alt+5"
},
{
"command": {
"action": "switchToTab",
"index": 5
},
"keys": "alt+6"
},
{
"command": {
"action": "switchToTab",
"index": 6
},
"keys": "alt+7"
},
{
"command": {
"action": "switchToTab",
"index": 7
},
"keys": "alt+8"
},
{
"command": {
"action": "switchToTab",
"index": 8
},
"keys": "alt+9"
},
//* End

//! To close the tab
{
"command": "closeTab",
"keys": "alt+q"
},

//! To close focused pane
{
"command": "closePane",
"keys": "alt+w"
},

//* To resize a pane
{
"command": {
"action": "resizePane",
"direction": "down"
},
"keys": "alt+shift+down"
},
{
"command": {
"action": "resizePane",
"direction": "left"
},
"keys": "alt+shift+left"
},
{
"command": {
"action": "resizePane",
"direction": "right"
},
"keys": "alt+shift+right"
},
{
"command": {
"action": "resizePane",
"direction": "up"
},
"keys": "alt+shift+up"
},
//* End

//* To split a pane within current profile
{
"command": {
"action": "splitPane",
"split": "horizontal"
},
"keys": "alt+h"
},
{
"command": {
"action": "splitPane",
"split": "vertical"
},
"keys": "alt+v"
},
//* End

//* To split a pane with another profile
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 0
},
"keys": "ctrl+alt+1"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 1
},
"keys": "ctrl+alt+2"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 2
},
"keys": "ctrl+alt+3"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 3
},
"keys": "ctrl+alt+4"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 4
},
"keys": "ctrl+alt+5"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 5
},
"keys": "ctrl+alt+6"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 6
},
"keys": "ctrl+alt+7"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 7
},
"keys": "ctrl+alt+8"
},
{
"command": {
"action": "splitPane",
"split": "auto",
"index": 8
},
"keys": "ctrl+alt+9"
},
//* End

//! To reset font size
{
"command": "resetFontSize",
"keys": "alt+r"
}
]
}