win11安装oh-my-posh,美化终端,提升你的开发效率

1,766 阅读1分钟

安装oh-my-posh, gsudo

winget install JanDeDobbeleer.OhMyPosh
winget install gsudo

打开window terminal,配置 image.png

给window terminal添加管理员权限,前面添加gsudo,后面添加 -NoLogo image.png

在终端输入以下指令,打开配置文件,配置oh-my-posh

notepad.exe $profile

将以下输入保存关闭

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\montys.omp.json" | Invoke-Expression

Set-PSReadLineOption -PredictionSource History # 设置预测文本来源为历史记录
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 # 设置向下键为前向搜索历史纪录

到这个网站下载字体:www.nerdfonts.com/font-downlo…

找到mononoki Nerd Font,下载安装。

安装输入提示扩展包

Install-Module posh-git -Scope CurrentUser
Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

重启电脑即可看到效果

image.png

录制_2022_07_21_15_05_48_649.gif

输入提示的操作,如果想要清除历史,可以输入以下指令

Remove-Item (Get-PSReadlineOption).HistorySavePath

如果想要手动清除某个隐私历史,可在以下位置编辑记录

C:\Users\DGBUAA\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine

但是修改了之后,会改变系统的环境变量,需要再配置环境变量。

%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem

参考文章:

blog.csdn.net/wn124534349…

juejin.cn/post/709537…

juejin.cn/post/697123…