PowerShell 安装 oh-my-posh

· · 科技·工程

字体安装

安装 Nerd font 字体:https://www.nerdfonts.com/font-downloads。

将压缩包下下来之后解压,安装里面的所有字体。

然后在 Windows Terminal 中设置字体,打开 Windows PowerShell,参照下图更改字体。

安装 PowerShellGet

以系统管理员权限打开 PowerShell 终端,执行以下命令:

Install-Module -Name PowerShellGet -Force

安装 oh-my-posh

以系统管理员权限打开 PowerShell 终端,执行以下命令:

winget install JanDeDobbeleer.OhMyPosh -s winget

安装 posh-git

以系统管理员权限打开 PowerShell 终端,执行以下命令:

PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force

安装 PSReadLine

以系统管理员权限打开 PowerShell 终端,执行以下命令:

Install-Module PSReadLine -Force

编辑 oh-my-posh 配置文件

以系统管理员权限打开 PowerShell 终端,执行以下命令:

$localThemePath = "C:\Users\admin\.oh-my-posh\themes"

New-Item -Path $localThemePath -ItemType Directory -Force

Invoke-WebRequest -Uri "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/jandedobbeleer.omp.json" -OutFile (Join-Path $localThemePath "jandedobbeleer.omp.json")

Test-Path (Join-Path $localThemePath "jandedobbeleer.omp.json") # 返回 True 即成功

然后输入:

notepad $PROFILE

会打开一个文件,在文件中写入:

$localThemePath = "C:\Users\admin\.oh-my-posh\themes"
oh-my-posh init pwsh --config "$localThemePath/jandedobbeleer.omp.json" | Invoke-Expression

再以系统管理员权限打开 PowerShell 终端,执行以下命令:

Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward

Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

Import-Module posh-git

保存修改,重新打开一个新的 PowerShell 终端,将会看到以下效果: