Windows Terminal美化(oh-my-posh3)

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

  1. 直接在微软商店搜索oh my posh下载(同时若没有Windows Terminal的可以安装一下Windows Terminal)

  2. 下载作者推荐MesloLGM NF字体,点此下载

下载完成后解压,全选右键点击安装即可自动安装

  1. 安装完成后打开Windows Terminal然后按”Ctrl+Shift+,(逗号)”来打开settings.json配置文件

将此处

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...

"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles": {
"defaults": {},
"list": [
{
...
}
]
}
...

改成

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...

"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"profiles": {
"defaults": {
"font": {
"face": "MesloLGM NF"
}
},
"list": [
{
...
}
]
}
...

  1. 编辑您的PowerShell配置文件脚本
1
notepad $PROFILE

第一次会显示找不到该文件,请确保先创建配置文件。命令如下

1
New-Item -Path $PROFILE -Type File -Force

然后运行

1
notepad $PROFILE

添加以下行。

1
oh-my-posh init pwsh | Invoke-Expression

PowerShell阻止运行本地脚本

在这种情况下,可能是PowerShell阻止运行本地脚本。为了解决这个问题,请使用Set-ExecutionPolicy RemoteSigned将PowerShell设置为仅需要签名的远程脚本,或者对配置文件进行签名。

1
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned 

然后回到Windows terminal新建一个powershell,即可看到以下内容
Windows terminal新建一个powershell

  1. 此处使用的是默认主题,若想修改主题,可以先使用以下命令
1
Get-PoshThemes

查看主题,然后在最下面可以找到主题文件的目录

1
2
3
4
5
6

Themes location: C:\Users\26535\AppData\Local\Programs\oh-my-posh\themes

To change your theme, adjust the init script in C:\Users\26535\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.
Example:
oh-my-posh init pwsh --config 'C:\Users\26535\AppData\Local\Programs\oh-my-posh\themes\negligible.omp.json' | Invoke-Expression

按住Ctrl点击该链接即可打开该文件夹,然后将所想要的主题的主题文件(一般都是”主题.omp.json”)路径复制下来,再到Windows Terminal中输入

1
notepad $profile

打开之前的配置文件,将文件路径加在此处(注意,前面要加上–config,后面文件路径要去除双引号)此处以negligible主题为例

1
oh-my-posh init pwsh --config 'C:\Users\26535\AppData\Local\Programs\oh-my-posh\themes\negligible.omp.json' | Invoke-Expression

使主题生效

1
. $PROFILE

效果
negligible

vscode 终端图标乱码,加字体解决
vscode 终端图标乱码