Win10终端美化指北

Win10终端美化指北

周所周知,win10下无论是cmd还是powershell都丑的一塌糊涂。

所以折腾了一波,把win10下的终端弄好看了一点,当然,和linux和mac的终端还是有差距。

最终效果:

PowerLine

在PowerShell里面安装PowerLine。

安装包括两个模块:

  • oh-my-posh上图中>G:\Code\Blog\blog>色块的效果。
  • post-git上图中master = + 43 ~5 -2的效果

如果只是在当前用户安装,打开PowerShell,输入

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

如果你使用管理员权限打开PowerShell并且想把oh-my-posh安装到所有用户,则输入

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

提示关于不可信的来源,输入Y表示同意即可。

安装完成后,输入

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

前两步导入模块,最后一步设置PowerLine主题。

如果你的电脑里没有安装Git,在输入Import-Module posh-git会报错,解决方法是安装Git或者把这一行去掉。

但是这次使用Import-Module的指令,再次启动PowerShell就会发现没有效果,这是因为这些指令仅限于本次会话的PowerShell有效,因此,若要使这一效果在每次启动的时候都有效,那就要将其添加到启动脚本中。

在PowerShell中输入code $profile ,然后输入以下内容,保存。如果你没有安装VS Code,则使用notepad $profile

1
2
3
4
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme AgnosterPlus
clear

如果提示禁止执行脚本之类的错误信息,请将脚本执行策略更改为RemoteSigned。使用具有管理员权限的PowerShell,然后输入

1
Set-ExecutionPolicy RemoteSigned

这样,在每次PoweShell打开的时候都能启用PowerLine主题。

sarasa-gothic-ttf

如果你在安装完oh-my-posh后,没有出现图片中显示的色块效果,比如像这样

口master口 +43 ~5 -2

这是因为你使用的字体不支持powerline里的插图,可以安装这款

Github-更纱黑体

安装ttf包即可。解压,里面有很多种,只需要找一种安装,如果全装了C盘会少很多个G的。例如我装的是sarasa-term-sc-的,将这个系列开头的10种不同状态的字体安装就行了。

然后你会发现powershell字体增加了更纱黑体选项。

PSColor

PSColor的作用是使目录下不同的文件高亮,类似linux系统里把文件夹蓝色高亮的效果。

和上面一样:

为所有用户安装 Install-Module PSColor

或者使用普通用户安装
Install-Module PSColor -Scope CurrentUser

安装完导入模块
Import-Module PSColor

加入初始话脚本notepad $profile

1
2
3
4
5
Import-Module posh-git
Import-Module oh-my-posh
Import-Module PSColor
Set-Theme AgnosterPlus
clear

本帖后文对此处有修改更新,如想自己动手,请看完后面的全文再操作

Fluent Terminal

专属 Windows 平台 UWP 的轻量终端模拟器。

github项目地址

win10的商店也上架了,搜索Fluent Terminal即可

以github为例:下载解压,右键点击 Install.ps1,选择使用 PowerShell 运行,安装完成。

如果不安装第三方终端,只用powershell,也会比原来好看很多:

题外

以上插件(PowerLine和PSColor)大概还有更好的替代,只要肯折腾。


更新修改

重装了windows10,发现windows terminal比fluent terminal加载速度更快,且支持标签栏。是更好的上位替代。

最终效果:

image-20210131223657835

windows terminal替代Fluent Terminal

去win10应用商店搜索安装即可。win10商店上架两个版本,即windows terminal和windows terminal precious。我装的前者。另外,本软件设置页非图形界面。
另外,此软件上架github:

https://github.com/microsoft/terminal

目前star数为71k,为前者7.6k的近十倍。

配置

官方文档贴:https://docs.microsoft.com/zh-cn/windows/terminal/custom-terminal-gallery/frosted-glass-theme

需要下载软件本体和额外一个字体:

本体:https://github.com/microsoft/terminal
字体:https://github.com/microsoft/cascadia-code/releases

对powershell的配置同上文,做到Fluent Terminal这步即可,下载完此软件后,新建标签页旁的下拉框进设置,是一份josn的配置文件,这是我的主题配置:

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
// This file was initially generated by Windows Terminal 1.5.10271.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.
"fontFace": "Cascadia Code PL",
"acrylicOpacity": 0.7,
"colorScheme" : "Frost",
"cursorColor" : "#000000",
"useAcrylic": true
},
"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
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"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
"theme": "light",
"schemes": [
{
"name" : "Frost",
"background" : "#FFFFFF",
"black" : "#3C5712",
"blue" : "#17b2ff",
"brightBlack" : "#749B36",
"brightBlue" : "#27B2F6",
"brightCyan" : "#13A8C0",
"brightGreen" : "#89AF50",
"brightPurple" : "#F2A20A",
"brightRed" : "#F49B36",
"brightWhite" : "#741274",
"brightYellow" : "#991070",
"cyan" : "#3C96A6",
"foreground" : "#000000",
"green" : "#6AAE08",
"purple" : "#991070",
"red" : "#8D0C0C",
"white" : "#6E386E",
"yellow" : "#991070"
}
],

// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"actions":
[
// 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" }
]
}

参考

Windows Terminal 美化实例

告别 Windows 终端的难看难用,从改造 PowerShell 的外观开始