可以安装PoweShell 7,也可以在默认的PoweShell环境中进行。
1、安装PSReadLine:
Install-Module -Name PSReadLine -AllowClobber -Force
2、安装posh-git:
Install-Module -Name posh-git -Force
3、安装on-my-posh:
winget install JanDeDobbeleer.OhMyPosh -s winget
4、配置PowerShell脚本运行权限:
Set-ExecutionPolicy RemoteSigned
5、创建配置文件:
notepad $Profile
导入上述模块:
Import-Module PSReadLine
Import-Module posh-git
6、配置PSReadLine,在配置文件中添加:
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -MaximumHistoryCount 1024
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
7、配置posh-git,选项可在网络上搜索,此处略;
8、配置on-my-posh,在配置文件中添加:
oh-my-posh init pwsh | Invoke-Expression
若需要指定主题,则添加:
oh-my-posh init pwsh --config 'C:\Users\xxx\AppData\Local\Programs\oh-my-posh\themes\jandedobbeleer.omp.json' | Invoke-Expression
9、保存关闭配置文件,重启Windows Terminal后生效。
10、字体设置:
on-my-posh工作基于Nerd系列字体,需要下载安装并选用,相关特殊字符方可正常显示。
Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher
若对已经提供的字体不满意,可以使用提供的font-patcher脚本自行对已有字体进行patch,生成nerd字体,以Windows环境为例,具体方法如下:
1)下载FontForge并安装;
2)将已有待patch字体文件复制到font-patcher目录下;
3)打开FontForge interactive console,并切换到font-patcher目录下,运行命令:
ffpython .\font-patcher .\xxx.ttf -c
等待完成,即会在该目录下生成patch后的nerd字体文件,安装即可。