一直觉得powershell和windows 终端不好看,今天就去美化了一下,我的最终效果:

image-20220723150848053

当然我们要折腾的ohmyposh的主题非常多,还可以自己设计,可以在这里查看自带的主题:官方文档

参考官方文档进行配置:Windows | Oh My Posh

在你即将安装ohmyposh的终端输入:

1
winget install JanDeDobbeleer.OhMyPosh -s winget

一条命令就解决了,是不是很简单呢?

如果嫌麻烦的话可以直接去微软应用商店搜索ohmyposh下载:点我 !

更新可以使用:

1
winget upgrade JanDeDobbeleer.OhMyPosh -s winget

安装好了ohmyposh自然需要配置了,在powershell中输入:

安装了vscode的可以使用:

1
code $profile

没有安装的或者不想用vscode配置的可以使用:

1
notepad $profile

在配置文件中加入:

1
2
3
4
5
6
7
Import-Module PSReadLine  ## 这个工具主要做命令提示管理等操作,默认集成在了 PowerShell 中,不需要安装
Set-PSReadlineKeyHandler -Key Tab -Function Complete ## 设置 Tab 键补全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete ## 设置 Ctrl+D 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo ## 设置 Ctrl+Z 为撤销
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward ## 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward ## 设置向下键为前向搜索历史记录
oh-my-posh init pwsh --config ~/Documents/PowerShell/themes/tonybaloney.omp.json | Invoke-Expression 主题路径 ## 设置主题,可以去https://ohmyposh.dev/docs/themes找

选主题可以直接在终端中输入:

1
Get-PoshThemes

来查看每个主题在该目录下的表现.

这样powershell就美化成功了!

This article was written on July 23, 2022.