525 字
3 分钟
Windows 终端美化指南:Oh My Posh + 主题 + 插件
2025-10-04
统计加载中...

快速开始#

安装 Oh My Posh#

前往 Oh My Posh 官网 查看详细安装说明。

Terminal window
winget install JanDeDobbeleer.OhMyPosh --source winget --scope user --force

如需为所有用户安装,将 --scope user 替换为 --scope machine

NOTE

如遇 PowerShell 脚本策略限制,可执行:

Terminal window
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine

安装 Nerd Font 字体#

推荐 JetBrainsMono Nerd Font

配置 PowerShell#

查找你的 $PROFILE 路径:

Terminal window
echo $PROFILE

若文件不存在,先创建:

Terminal window
New-Item -Path $PROFILE -Type File -Force

编辑配置文件,添加:

Terminal window
oh-my-posh init pwsh | Invoke-Expression

重启终端即可生效。

个性化主题#

主题库见 官方主题库

如选用 1_shell 主题,在 PowerShell 配置文件中添加:

Terminal window
oh-my-posh init pwsh --config "https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/1_shell.omp.json" | Invoke-Expression

重启终端即可看到新主题效果。

插件推荐#

PSReadLine 自动补全#

安装:

Terminal window
Install-Module PSReadLine -Scope CurrentUser -Force

$PROFILE 中添加:

Terminal window
Import-Module PSReadLine
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

效果:

Terminal window
 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]
Terminal window
 xxx on Saturday at 1:58 PM 0s   MEM: 95% (15/15GB)
 {  home }  .\Links\
Links LockAppHost.exe
Local Settings LockScreenContentServer.exe
L: lodctr.exe
label.exe logagent.exe
LanguageComponentsInstallerComHandler.exe logman.exe
launcher.exe logoff.exe
LaunchTM.exe LogonUI.exe
LaunchWinApp.exe lp
LegacyNetUXHost.exe lpkinstall.exe
LicenseManagerShellext.exe lpksetup.exe
licensingdiag.exe lpremove.exe
LicensingUI.exe ls
Limit-EventLog LsaIso.exe
LocationNotificationWindows.exe lsass.exe
Locator.exe ltedit.bat
Lock-BitLocker lusrmgr.msc
Terminal window
 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 Games
3D Objects Desktop Local Settings OpenVPN Searches
AppData Documents Music Pictures SendTo
Application Data Downloads My Documents PrintHood Templates

ZLocation 目录跳转#

安装:

Terminal window
Install-Module ZLocation -Scope CurrentUser

$PROFILE 中添加:

Terminal window
Import-Module ZLocation

效果:

Terminal window
 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 } 

我的完整配置示例#

Terminal window
oh-my-posh init pwsh --config "https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/1_shell.omp.json" | Invoke-Expression
Import-Module PSReadLine
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Import-Module ZLocation

卸载与清理#

  1. 卸载 Oh My Posh:
    Terminal window
    winget uninstall JanDeDobbeleer.OhMyPosh
  2. 卸载 PowerShell 模块:
    Terminal window
    Uninstall-Module oh-my-posh -AllVersions
  3. 删除配置文件:
    Terminal window
    Remove-Item $env:POSH_PATH -Force -Recurse -ErrorAction SilentlyContinue
    Remove-Item $env:USERPROFILE\.config\ohmyposh -Force -Recurse -ErrorAction SilentlyContinue
  4. 编辑 PowerShell 配置文件($PROFILE),移除相关配置。
Windows 终端美化指南:Oh My Posh + 主题 + 插件
https://www.trtyr.top/posts/windows-terminal-beautify-oh-my-posh/
作者
特让他也让
发布于
2025-10-04
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时