525 字
3 分钟
Windows 终端美化指南:Oh My Posh + 主题 + 插件
快速开始
安装 Oh My Posh
前往 Oh My Posh 官网 查看详细安装说明。
winget install JanDeDobbeleer.OhMyPosh --source winget --scope user --force
如需为所有用户安装,将 --scope user
替换为 --scope machine
。
NOTE如遇 PowerShell 脚本策略限制,可执行:
Terminal window
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
安装 Nerd Font 字体
配置 PowerShell
查找你的 $PROFILE
路径:
echo $PROFILE
若文件不存在,先创建:
New-Item -Path $PROFILE -Type File -Force
编辑配置文件,添加:
oh-my-posh init pwsh | Invoke-Expression
重启终端即可生效。
个性化主题
主题库见 官方主题库。
如选用 1_shell
主题,在 PowerShell 配置文件中添加:
oh-my-posh init pwsh --config "https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/1_shell.omp.json" | Invoke-Expression
重启终端即可看到新主题效果。
插件推荐
PSReadLine 自动补全
安装:
Install-Module PSReadLine -Scope CurrentUser -Force
在 $PROFILE
中添加:
Import-Module PSReadLineSet-PSReadLineOption -PredictionViewStyle ListViewSet-PSReadLineOption -PredictionSource HistorySet-PSReadLineOption -HistorySearchCursorMovesToEndSet-PSReadLineKeyHandler -Key Tab -Function MenuComplete
效果:
xxx on Saturday at 1:57 PM 0.016s MEM: 95% (15/15GB) { home } cle<-/4> <History(4)>> clear [History]> cleart [History]> clea [History]> cd 'D:\$RECYCLE.BIN\' [History]
xxx on Saturday at 1:58 PM 0s MEM: 95% (15/15GB) { home } .\Links\Links LockAppHost.exeLocal Settings LockScreenContentServer.exeL: lodctr.exelabel.exe logagent.exeLanguageComponentsInstallerComHandler.exe logman.exelauncher.exe logoff.exeLaunchTM.exe LogonUI.exeLaunchWinApp.exe lpLegacyNetUXHost.exe lpkinstall.exeLicenseManagerShellext.exe lpksetup.exelicensingdiag.exe lpremove.exeLicensingUI.exe lsLimit-EventLog LsaIso.exeLocationNotificationWindows.exe lsass.exeLocator.exe ltedit.batLock-BitLocker lusrmgr.msc
xxx on Saturday at 1:58 PM 0s MEM: 95% (15/15GB) { home } cd .\.vscode\.vscode Contacts Favorites NetHood Recent Videos「开始」菜单 Cookies Links OneDrive Saved Games3D Objects Desktop Local Settings OpenVPN SearchesAppData Documents Music Pictures SendToApplication Data Downloads My Documents PrintHood Templates
ZLocation 目录跳转
安装:
Install-Module ZLocation -Scope CurrentUser
在 $PROFILE
中添加:
Import-Module ZLocation
效果:
z
Weight Path------ ---- 6 C:\Users\xxx 0 C:\Users\xxx\Desktop 0 C:\Users\xxx\Documents 0 C:\Users\xxx\Documents\WindowsPowerShell 0 C:\Users\xxx\Downloads 0 C:\Users\xxx\Pictures 0 D:\Env 0 D:\Env\Rust 0 D:\SoftWare 0 E:\Document\配置备份\chatwise.zip
z env pwd
Path----D:\Env
z - pwd
Path----C:\Users\xxx
xxx on Saturday at 2:04 PM 0s MEM: 95% (15/15GB) { home }
我的完整配置示例
oh-my-posh init pwsh --config "https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/1_shell.omp.json" | Invoke-ExpressionImport-Module PSReadLineSet-PSReadLineOption -PredictionViewStyle ListViewSet-PSReadLineOption -PredictionSource HistorySet-PSReadLineOption -HistorySearchCursorMovesToEndSet-PSReadLineKeyHandler -Key Tab -Function MenuCompleteImport-Module ZLocation
卸载与清理
- 卸载 Oh My Posh:
Terminal window winget uninstall JanDeDobbeleer.OhMyPosh - 卸载 PowerShell 模块:
Terminal window Uninstall-Module oh-my-posh -AllVersions - 删除配置文件:
Terminal window Remove-Item $env:POSH_PATH -Force -Recurse -ErrorAction SilentlyContinueRemove-Item $env:USERPROFILE\.config\ohmyposh -Force -Recurse -ErrorAction SilentlyContinue - 编辑 PowerShell 配置文件(
$PROFILE
),移除相关配置。
Windows 终端美化指南:Oh My Posh + 主题 + 插件
https://www.trtyr.top/posts/windows-terminal-beautify-oh-my-posh/ 部分信息可能已经过时