oh-my-posh 美化你的终端

1
2
3
4
5
6
"useAcrylic": true, 
"acrylicOpacity": 0.8,

//自定义终端壁纸
"backgroundImage": "E:/xiaoyu/Pictures/234549-1669045549622d.jpg",
"backgroundImageOpacity": 0.6,
  • 通过scoop安装oh-my-posh
1
scoop install oh-my-posh
  • 查看oh-my-posh在那个shell运行
1
oh-my-posh get shell
  • 编辑配置文件
1
notepad $PROFILE
  • 新建配置文件
1
New-Item -Path $PROFILE -Type File -Force
  • 查看所有主题
1
Get-PoshThemes
  • 加载配置文件内容
1
2
3
 oh-my-posh init pwsh --config 'C:\Scoop\apps\oh-my-posh\current\themes\kushal.omp.json' | Invoke-Expression

& ([ScriptBlock]::Create((oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" --print) -join "`n"))
  • 重新加载配置文件,让其生效
1
. $PROFILE
  • oh-my-posh安装博客
1
https://juejin.cn/post/7210596158934433853
  • 安装模块
1
2
3
4
5
6
7
8
9
10
# PSReadLine 提供了语法高亮、错误提示、多行编辑、键绑定、历史记录搜索等功能
Install-Module PSReadLine
# posh-git 可以在 PowerShell 中显示 Git 状态信息,并提供 Git 命令的自动补全
Install-Module posh-git
# oh-my-posh 提供了多种自定义主题和配色,可以让 PowerShell 更美观实用
Install-Module oh-my-posh
# Oh My Posh 中使用了很多图标字体,需要正常显示图标,需要安装一个 Nerd 字体,并修改 PowerShell 配置
oh-my-posh font install

sudo Install-Module -Name Terminal-Icons -Repository PSGallery
  • 配置文件加载
1
Import-Module -Name Terminal-Icons
  • 加载配置
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
#------------------------------- Import Modules BEGIN -------------------------------
# 引入 ps-read-line
Import-Module PSReadLine

# 引入 posh-git
#Import-Module posh-git

# 引入 oh-my-posh
#Import-Module oh-my-posh

# 引入Terminal-Icons
Import-Module -Name Terminal-Icons

# 设置 PowerShell 主题
# Set-PoshPrompt ys
#Set-PoshPrompt emodipt-extend
#------------------------------- Import Modules END -------------------------------

#------------------------------- Set Hot-keys BEGIN -------------------------------
# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History

# 每次回溯输入历史,光标定位于输入内容末尾
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

# 设置 Tab 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete

# 设置 Ctrl+d 为退出 PowerShell
Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit

# 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo

# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward

# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
#------------------------------- Set Hot-keys END -------------------------------