CMD美化及功能增强: Clink + Oh My Posh + Fastfetch + msys2

Linux终端美化:https://blog.lololowe.com/posts/dd02/

Windows Terminal

发行版地址:https://github.com/microsoft/terminal/releases/latest

下载msixbundle安装包,然后双击安装即可升级到最新版。

主题:Oh My Posh

官网:https://ohmyposh.dev/docs/installation/windows

CRXsoso: https://www.crxsoso.com/store/detail/xp8k0hkjfrxgck

在线预览所有主题: https://ohmyposh.dev/docs/themes

Nerd字体

官网:https://www.nerdfonts.com/font-downloads

推荐 0xProto Nerd Font

CMD增强:Clink

官网:https://chrisant996.github.io/clink/

安装完成后重启Windows Terminal中的CMD,然后输入clink info命令获取插件目录:

alt text

打开插件目录,创建oh-my-posh.lua脚本,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
load(io.popen('oh-my-posh init cmd --config C:\\Users\\%username%\\AppData\\Local\\Programs\\oh-my-posh\\themes\\hunk.omp.json'):read("*a"))()

-- 在线预览所有主题:https://ohmyposh.dev/docs/themes

-- 推荐主题:
-- powerlevel10k_classic
-- hunk
-- sim-web
-- kali
-- kushal
-- hul10
-- honukai
-- craver
-- amro

替换主题只需修改hunk为其他主题名称即可。

开启“瞬态提示符”(transient prompt): clink set prompt.transient same_dir
去掉启动banner:clink autorun install -- --quiet

详细教程:https://halc.top/p/82bd449c

下一代ls命令: lsd

项目地址:https://github.com/lsd-rs/lsd

安装: winget install --id lsd-rs.lsd

系统配置显示:Fastfetch

项目地址:https://github.com/fastfetch-cli/fastfetch#windows

使用winget安装会自动配置环境变量: sudo winget install fastfetch

为了让cmd启动时自动运行fastfetch,再次打开clink插件目录,创建clink_startup.lua脚本,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
-- 切换到指定目录
os.execute('cd /d E:\\User\\lololowe\\Desktop')

-- 设置 doskey 别名
os.execute('doskey ll=lsd -lFha')
os.execute('doskey pwd=cd')
os.execute('doskey clear=cls')

-- 运行fastfetch
os.execute('C:\\Users\\%username%\\AppData\\Local\\Microsoft\\WinGet\\Links\\fastfetch.exe')

-- 设置中文编码并隐藏输出(fastfetch会导致chcp 936失效)
os.execute('chcp 936>nul')

fastfetch配置文件(%userprofile%\.config\fastfetch\config.jsonc)如下:

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
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "builtin",
"source": "windows",
"height": 18,
"padding": {
"top": 5
}
},
"display": {
"separator": " : "
},
"modules": [
{
// https://www.nerdfonts.com/cheat-sheet
"type": "custom",
"format": "\u001b[36m  OS Info"
},
{
"type": "custom",
"format": "┌────────────────────────────────────────────────────────┐"
},
{
"type": "os",
"key": "  OS",
"keyColor": "red"
},
{
"type": "kernel",
"key": " 󰻹 Kernel",
"keyColor": "red"
},
{
"type": "host",
"key": "  Machine",
"format": "{name}{?vendor}",
"keyColor": "red"
},
{
"type": "display",
"key": " 󰹑 Display",
"format": "{1}x{2} @ {3} Hz",
"keyColor": "red"
},
{
"type": "uptime",
"key": " 󱫐 Uptime ",
"keyColor": "red"
},
{
"type": "shell",
"key": "  Shell",
"keyColor": "red"
},

{
"type": "custom",
"format": "└────────────────────────────────────────────────────────┘"
},
"break",
{
"type": "title",
"key": " "
},
{
"type": "custom",
"format": "┌────────────────────────────────────────────────────────┐"
},

{
"type": "cpu",
"format": "{1}",
"key": "  CPU",
"keyColor": "blue"
},
{
"type": "gpu",
"format": "{2} {7}",
"key": " 󰋵 GPU",
"keyColor": "blue"
},

{
"type": "disk",
"key": "  Disk",
"keyColor": "magenta"
},
{
"type": "memory",
"key": "  Memory",
"keyColor": "magenta"
},
{
"type": "bluetooth",
"key": "  Bluetooth",
"keyColor": "magenta"
},
{
"type": "wifi",
"key": "  WiFi",
"keyColor": "magenta"
},
{
"type": "localip",
"showIpv6": false,
"showMac": false,
"showSpeed": false,
"showMtu": false,
"showLoop": false,
"showFlags": false,
"showAllIps": false,
"key": " 󱦂 LAN",
"keyColor": "magenta"
},
{
"type": "publicip",
"timeout": 500,
"url": "http://4.ipw.cn",
"key": " 󰩟 WAN",
"keyColor": "magenta"
},
{
"type": "dns",
"key": " 󰮌 DNS",
"keyColor": "magenta"
},

{
"type": "custom",
"format": "└────────────────────────────────────────────────────────┘"
},
{
"type": "colors",
"paddingLeft": 2,
"symbol": "circle"
},
"break"
]
}

效果如下:

alt text

更多好看的配置:https://github.com/sqlsec/fastfetch

类unix操作环境:msys2

官网:https://www.msys2.org/

这里下载msys2主要是为了使用里面的unix工具,比如git,vim,wget等,以及一些编译工具,比如gcc,gdb等。

安装完成后将msys2安装目录下的`usr/bin/目录添加到环境变量中,就可以在cmd中调用msys2的工具了。

msys2换源:
1. 中科大源: https://mirrors.ustc.edu.cn/help/msys2.html
2. 清华源: https://mirrors.tuna.tsinghua.edu.cn/help/msys2/

安装常用工具:

1
2
3
pacman -Sy  # 更新软件包数据库
pacman -S vim git gcc gdb tmux whois zsh
pacman -Qe # 查看pacman已安装的软件包

msys2添加到Windows Terminal中的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"backgroundImage": "E:\\user\\lololowe\\Pictures\\\u58c1\u7eb8\\hanfu\\hanfu4.jpg",
"backgroundImageOpacity": 0.25,
"commandline": "D:\\Apps\\msys64\\msys2_shell.cmd -defterm -no-start -ucrt64 -here -shell zsh -use-full-path",
"font":
{
"face": "0xProto Nerd Font Mono",
"size": 15
},
"guid": "{9979ff10-bac7-4dac-9ae2-20a77c7142f5}",
"hidden": false,
"icon": "D:\\Apps\\msys64\\ucrt64.ico",
"name": "MSYS2",
"startingDirectory": "E:\\User\\lololowe",
"useAcrylic": true
},

msys2的美化教程(ZSH+Oh My Posh): https://github.com/wszqkzqk/wszqkzqk.github.io/blob/master/_posts/2022-06-24-%E5%9C%A8%E4%B8%8D%E5%80%9F%E5%8A%A9oh-my-zsh%E7%9A%84%E5%89%8D%E6%8F%90%E4%B8%8B%E8%BF%9B%E8%A1%8CZsh%E9%85%8D%E7%BD%AE.md