最近在win10下面搭建了一个 WSL+cmder+oh-my-zsh 的程序员命令行环境,为什么呢?还不是买不起mac,加上自己的黑苹果瘫了,所有又回到了win10上面。不过上面不管是Cmd还是PowerShell都是难看的要死要死的,而且很多命令不支持,所以有了这一次的实践。
更新于2019年9月28日
之前我们使用的是 cmder
这个工具。
在 windows 1903 以及以后的版本中,可以直接使用windows自带的 windows terminal
,可以直接从windwos 10 的应用商店里面下载。这个比 cmder 用起来更加的便捷。
检查window版本: windows + R 后 输入 winver
安装 windows terminal 以后我们可以自己去配置 terminal 的样式。
修改配置如下,其中 #XXX
为注释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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447{
"$schema": "https://aka.ms/terminal-profiles-schema",
"globals" :
{
"alwaysShowTabs" : true,
"copyOnSelect" : true,
"defaultProfile" : "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}", #默认的终端,点击+号
"initialCols" : 120,
"initialRows" : 30,
"keybindings" :
[
{
"command" : "closePane",
"keys" :
[
"ctrl+shift+w"
]
},
{
"command" : "copy",
"keys" :
[
"ctrl+shift+c"
]
},
{
"command" : "duplicateTab",
"keys" :
[
"ctrl+shift+d"
]
},
{
"command" : "newTab",
"keys" :
[
"ctrl+shift+t"
]
},
{
"command" : "newTabProfile0",
"keys" :
[
"ctrl+shift+1"
]
},
{
"command" : "newTabProfile1",
"keys" :
[
"ctrl+shift+2"
]
},
{
"command" : "newTabProfile2",
"keys" :
[
"ctrl+shift+3"
]
},
{
"command" : "newTabProfile3",
"keys" :
[
"ctrl+shift+4"
]
},
{
"command" : "newTabProfile4",
"keys" :
[
"ctrl+shift+5"
]
},
{
"command" : "newTabProfile5",
"keys" :
[
"ctrl+shift+6"
]
},
{
"command" : "newTabProfile6",
"keys" :
[
"ctrl+shift+7"
]
},
{
"command" : "newTabProfile7",
"keys" :
[
"ctrl+shift+8"
]
},
{
"command" : "newTabProfile8",
"keys" :
[
"ctrl+shift+9"
]
},
{
"command" : "nextTab",
"keys" :
[
"ctrl+tab"
]
},
{
"command" : "openNewTabDropdown",
"keys" :
[
"ctrl+shift+space"
]
},
{
"command" : "openSettings",
"keys" :
[
"ctrl+,"
]
},
{
"command" : "paste",
"keys" :
[
"ctrl+shift+v"
]
},
{
"command" : "prevTab",
"keys" :
[
"ctrl+shift+tab"
]
},
{
"command" : "scrollDown",
"keys" :
[
"ctrl+shift+down"
]
},
{
"command" : "scrollDownPage",
"keys" :
[
"ctrl+shift+pgdn"
]
},
{
"command" : "scrollUp",
"keys" :
[
"ctrl+shift+up"
]
},
{
"command" : "scrollUpPage",
"keys" :
[
"ctrl+shift+pgup"
]
},
{
"command" : "switchToTab0",
"keys" :
[
"ctrl+alt+1"
]
},
{
"command" : "switchToTab1",
"keys" :
[
"ctrl+alt+2"
]
},
{
"command" : "switchToTab2",
"keys" :
[
"ctrl+alt+3"
]
},
{
"command" : "switchToTab3",
"keys" :
[
"ctrl+alt+4"
]
},
{
"command" : "switchToTab4",
"keys" :
[
"ctrl+alt+5"
]
},
{
"command" : "switchToTab5",
"keys" :
[
"ctrl+alt+6"
]
},
{
"command" : "switchToTab6",
"keys" :
[
"ctrl+alt+7"
]
},
{
"command" : "switchToTab7",
"keys" :
[
"ctrl+alt+8"
]
},
{
"command" : "switchToTab8",
"keys" :
[
"ctrl+alt+9"
]
}
],
"requestedTheme" : "system",
"showTabsInTitlebar" : true,
"showTerminalTitleInTitlebar" : true,
"wordDelimiters" : " ./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}~?\u2502"
},
"profiles" :
[
{
"acrylicOpacity" : 0.5,
"backgroundImage": "C://Users//Administrator//Pictures//Saved Pictures//2.jpg", #背景图片
"backgroundImageOpacity" : 0.6, #背景透明度
"background" : "#012456",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "powershell.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code", #字体
"fontSize" : 12,
"guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", #终端唯一编号
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
"name" : "Windows PowerShell", #启动的终端
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : false,
"tabTitle" : "Powershell"
},
{
"acrylicOpacity" : 0.75,
"backgroundImage": "C://Users//Administrator//Pictures//Saved Pictures//1.jpg",
"backgroundImageOpacity" : 0.6,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"commandline" : "cmd.exe",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code",
"fontSize" : 12,
"guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
"name" : "cmd",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
{
"acrylicOpacity" : 0.59999999999999998,
"closeOnExit" : false,
"colorScheme" : "Vintage",
"commandline" : "Azure",
"connectionType" : "{d9fcfdfa-a479-412c-83b7-c5640e61cd62}",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code",
"fontSize" : 12,
"guid" : "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"historySize" : 9001,
"icon" : "ms-appx:///ProfileIcons/{b453ae62-4e3d-5e58-b989-0a998ec441b8}.png",
"name" : "Azure Cloud Shell",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"startingDirectory" : "%USERPROFILE%",
"useAcrylic" : true
},
{
"acrylicOpacity" : 0.5,
"backgroundImage": "C://Users//Administrator//Pictures//Saved Pictures//3.jpg",
"backgroundImageOpacity" : 0.4,
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"name": "Ubuntu-18.04",
"closeOnExit" : true,
"colorScheme" : "Campbell",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Cascadia Code",
"fontSize" : 12,
"source": "Windows.Terminal.Wsl",
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"historySize" : 9001,
"tabTitle" : "Ubuntu (WSL)",
"useAcrylic" : false
}
],
"schemes" :
[
{
"background" : "#0C0C0C",
"black" : "#0C0C0C",
"blue" : "#0037DA",
"brightBlack" : "#767676",
"brightBlue" : "#3B78FF",
"brightCyan" : "#61D6D6",
"brightGreen" : "#16C60C",
"brightPurple" : "#B4009E",
"brightRed" : "#E74856",
"brightWhite" : "#F2F2F2",
"brightYellow" : "#F9F1A5",
"cyan" : "#3A96DD",
"foreground" : "#CCCCCC",
"green" : "#13A10E",
"name" : "Campbell",
"purple" : "#881798",
"red" : "#C50F1F",
"white" : "#CCCCCC",
"yellow" : "#C19C00"
},
{
"background" : "#000000",
"black" : "#000000",
"blue" : "#000080",
"brightBlack" : "#808080",
"brightBlue" : "#0000FF",
"brightCyan" : "#00FFFF",
"brightGreen" : "#00FF00",
"brightPurple" : "#FF00FF",
"brightRed" : "#FF0000",
"brightWhite" : "#FFFFFF",
"brightYellow" : "#FFFF00",
"cyan" : "#008080",
"foreground" : "#C0C0C0",
"green" : "#008000",
"name" : "Vintage",
"purple" : "#800080",
"red" : "#800000",
"white" : "#C0C0C0",
"yellow" : "#808000"
},
{
"background" : "#282C34",
"black" : "#282C34",
"blue" : "#61AFEF",
"brightBlack" : "#5A6374",
"brightBlue" : "#61AFEF",
"brightCyan" : "#56B6C2",
"brightGreen" : "#98C379",
"brightPurple" : "#C678DD",
"brightRed" : "#E06C75",
"brightWhite" : "#DCDFE4",
"brightYellow" : "#E5C07B",
"cyan" : "#56B6C2",
"foreground" : "#DCDFE4",
"green" : "#98C379",
"name" : "One Half Dark",
"purple" : "#C678DD",
"red" : "#E06C75",
"white" : "#DCDFE4",
"yellow" : "#E5C07B"
},
{
"background" : "#FAFAFA",
"black" : "#383A42",
"blue" : "#0184BC",
"brightBlack" : "#4F525D",
"brightBlue" : "#61AFEF",
"brightCyan" : "#56B5C1",
"brightGreen" : "#98C379",
"brightPurple" : "#C577DD",
"brightRed" : "#DF6C75",
"brightWhite" : "#FFFFFF",
"brightYellow" : "#E4C07A",
"cyan" : "#0997B3",
"foreground" : "#383A42",
"green" : "#50A14F",
"name" : "One Half Light",
"purple" : "#A626A4",
"red" : "#E45649",
"white" : "#FAFAFA",
"yellow" : "#C18301"
},
{
"background" : "#002B36",
"black" : "#073642",
"blue" : "#268BD2",
"brightBlack" : "#002B36",
"brightBlue" : "#839496",
"brightCyan" : "#93A1A1",
"brightGreen" : "#586E75",
"brightPurple" : "#6C71C4",
"brightRed" : "#CB4B16",
"brightWhite" : "#FDF6E3",
"brightYellow" : "#657B83",
"cyan" : "#2AA198",
"foreground" : "#839496",
"green" : "#859900",
"name" : "Solarized Dark",
"purple" : "#D33682",
"red" : "#DC322F",
"white" : "#EEE8D5",
"yellow" : "#B58900"
},
{
"background" : "#FDF6E3",
"black" : "#073642",
"blue" : "#268BD2",
"brightBlack" : "#002B36",
"brightBlue" : "#839496",
"brightCyan" : "#93A1A1",
"brightGreen" : "#586E75",
"brightPurple" : "#6C71C4",
"brightRed" : "#CB4B16",
"brightWhite" : "#FDF6E3",
"brightYellow" : "#657B83",
"cyan" : "#2AA198",
"foreground" : "#657B83",
"green" : "#859900",
"name" : "Solarized Light",
"purple" : "#D33682",
"red" : "#DC322F",
"white" : "#EEE8D5",
"yellow" : "#B58900"
}
]
}
上面我们用到了 Cascadia Code
字体。这里在推荐一下这个字体,这个月微软为编程人员出的一款字体,用起来简直舒服。
下载地址
安装WSL
win10系统需要更新到1067及其以后的版本,并且是64位的系统才可以安装。相信做开发的都是64位系统吧。
win10打开程序和功能
勾选适用于系统的Linux的子系统,然后重启系统。
重启以后,此时我们已经可以使用Linux系统,但是我们还差一个系统,所以需要安装一个
我们在win10应用商店里面搜索linux,安装Ubuntu。
安装完成后在开始菜单里面找到程序,启动。
刚开始的时候需要等一下,在配置环境。完成后需要设置用户名以及密码。
安装cmder
cmder有两个版本,Mini版与完整版(包含了git以及一些其他的命令)。推荐安装完整版。
安装完成后打开,我们需要进行配置一下
如上图,在tasks中添加一个task
- 名字为Ubuntu,这个名字随便你
- 下面的大框里面
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl --distro-guid={9df562ee-848c-4af4-ab4e-aedad54ceba9} -cur_console:pm:/mnt
。这里面的9df562ee-848c-4af4-ab4e-aedad54ceba9
指的是Ubuntu的唯一标识符,如果重装了子系统,那么这个标识符实惠变得。可以在在注册表(regedit)中查找计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss
。win+R搜索regedit
。
在常规里面设置刚刚的名字为默认的启动项。如果你要打开其他的,比如cmd,可以点窗口右下角的+
,里面有所有的配置。
安装oh-my-zsh
在Ubuntu系统中使用命令行而不是win中
安装任何包之前一定要先更新!sudo apt-get update
安装zshsudo apt-get install zsh
安装oh-my-zshsh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
安装成功
如果 遇到证书类似问题
apt-get install ca-certificates
自动启动zshvim ~/.bashrc
或者nano ~/.bashrc
(推荐使用)打开编辑.bashrc
文件,添加以下内容:1
2
3if test -t 1; then
exec zsh
fi
如果你使用的是vim ~/.bashrc
,编辑后使用:wq
退出。
如果你使用的是nano ~/.bashrc
,使用Ctrl+Shift+X
保存并退出。
修改主题:1
2
3
4nano ~/.zshrc
# 主题名字ys,你可以搜索其他的主题使用,ys挺好的
ZSH_THEME="ys"
修改以后保存。
终端字体补全sudo apt-get install fonts-powerline
客户端字体补全
注意: 有些字符在windows 上无法显示,所以需要安装字体
nerdfonts.com,选择 Hack
修改cmder字体为
当然,你也可以设置为其他你认为好看的字体。
这个是我的配置的最后的效果,还设置了透明度以及背景什么的,你们也可以自己进行配置。
在VSCode上使用WSL
由于博主是做前端开发的,用的是VSCode所以这里说一下,怎么在VSCode上面使用。
在VSCode的设置文件中添加这一句1
"terminal.integrated.shell.windows": "C:\\\\Windows\\\\System32\\\\wsl.exe",
如果需要使用node,npm等工具,WSL里面是不能够直接使用windows自带的这些环境变量的,我们需要在WSL中安装,具体的安装方法可以google–Ubuntu安装软件
说在结尾
之前说的字体fonts-powerline
,Hack Nerd Font Mono
这个字体,其实还是挺好看的,大家可以使用,包括在PC上面也可以。这个字体可以使用Git下载https://github.com/powerline/fonts
,不过这个实在是有点慢,这里我已经下载下来放在了这里。
下载下来以后使用PowerShell
,到字体目录下,运行以下命令1
.\install.ps1
可能会遇到报错,此时先执行set-Executionpolicy Remotesigned
关于启动时候报错
有时候我们启动子系统的时候会报错,错误代码:0x800703fa
具体错误内容:WslRegisterDistribution failed with error: 0x800703fa
此时win+R
在运行窗口中执行“services.msc”指令,在本地服务中重启 LxssManager 服务即可
参考文献
[1]. https://segmentfault.com/a/1190000016827068
[2]. https://blog.joaograssi.com/windows-subsystem-for-linux-with-oh-my-zsh-conemu/