
终端美化神器 oh-my-posh 全面教程,涵盖 Windows 与 Linux 系统的安装方法、字体配置、主题设置与 VS Code 集成,详解自定义主题 JSON 文件结构,附带作者推荐主题与常见问题解决方案,助你打造个性化高颜值终端环境。
终端美化
windows
下载oh-my-posh
1
winget install JanDeDobbeleer.OhMyPosh -s winget
使用管理员身份执行
下载字体
1
oh-my-posh font install
上下键选择,推荐
Cousine
,看起来很舒服(如上图)。打开powershell(推荐windows terminal打开)
在界面里输入快捷键
CTRL + SHIFT + ,
打开终端配置文件,输入以下配置。1
2
3
4
5
6
7"defaults":
{
"font":
{
"face": "Cousine" //填入你实际下载的字体名称
}
},或者直接打开terminal的默认设置,选择字体。
vscode里设置
打开设置选项,输入
Integrated: Font Family
,填入下载的字体即可。设置主题
1
2New-Item -Path $PROFILE -Type File -Force //如果$Profile不存在,就执行这个
notepad $PROFILE在弹出的文件里写入
1
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/ys.omp.json" | Invoke-Expression
其中
ys.omp.json
是主题配置文件,你可以自选。最后保存配置文件
1
. $PROFILE
以上过程如有任何问题,可能解决方法如下
- 管理员身份执行命令
- 执行 Install-Module PsReadLine -Force
主题选择
1
Get-PoshThemes
会列出很多主题,你可以自己选择,甚至可以进入配置文件进行修改(文件地址在上面命令输出的最后几行)。
个人使用的主题
ys.omp.json
,在此基础上修改了一些,主打一个清爽,不是很花里胡哨😀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{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "white",
"properties": {
"fetch_version": false
},
"style": "plain",
"template": "({{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }})",
"type": "python"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": false,
"segments": [
{
"foreground": "lightBlue",
"style": "plain",
"template": "# ",
"type": "text"
},
{
"foreground": "red",
"style": "plain",
"template": " % ",
"type": "root"
},
{
"style": "plain",
"template": "<cyan>{{ .UserName }}</><darkGray>@</><green>{{ .HostName }}</>",
"type": "session"
},
{
"foreground": "lightYellow",
"properties": {
"style": "full"
},
"style": "plain",
"template": " {{ .Path }} ",
"type": "path"
},
{
"style": "plain",
"template": "<darkGray>on</> <white>{{.RepoName}}:</><cyan>{{ .HEAD }}</>{{ if .Working.Changed }}<red> x</>{{ end }} ",
"type": "git",
"properties": {
"fetch_status": true
}
},
{
"foreground": "darkGray",
"style": "plain",
"template": "[{{ .CurrentDate | date .Format }}]",
"type": "time"
},
{
"foreground": "red",
"style": "plain",
"template": " C:{{ if gt .Code 0 }}{{ .Code }}{{ end }} ",
"type": "status"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "lightRed",
"style": "plain",
"template": "$",
"type": "text"
}
],
"type": "prompt"
}
],
"final_space": true,
"version": 2
}
Linux
ubuntu 18.04
下载
1
curl -s https://ohmyposh.dev/install.sh | bash -s
安装font和windows一样
设置主题
首先区分你是要对所有用户都设置,还是只对当前用户?
当前用户
~/.bashrc
所有用户(包括root)
etc/bash.bashrc
将下面的命令添加到上面的bash配置文件中第一行。
1
eval "$(oh-my-posh init bash --config $theme_path)"
$theme_path
是你保存主题文件的地方,在安装的时候会有信息,仔细找一下。如果你是对所有用户设置,记得把主题文件放在所有用户都能访问的地方,并且设置文件权限所有用户可读取。
例如,copy一份放在/usr/src里
最后
source
bash配置文件即可。主题选择都和windows一样。
欢迎加我好友一起学习😎
本文作者:Decade 作者博客:https://decade.net.cn/ 联系方式:Github QQ:3237550600 转载要求: 转载请在文首显眼出表明本文链接且在留言区告知我并附上你转载到哪里的链接。