概述:Windows Terminal 美化配置指南,使用 oh-my-posh 打造个性化终端。

0x01、效果预览

美化后的终端效果:

  • 状态信息显示(当前目录、Git 状态、执行时间等)
  • 丰富的主题选择
  • 图标和颜色自定义

0x02、安装 oh-my-posh

通过 winget 安装

winget install JanDeDobbeleer.OhMyPosh

通过 Scoop 安装

scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

通过 Chocolatey 安装

choco install oh-my-posh

0x03、安装字体

为了正确显示图标,需要安装 Nerd 字体:

# 使用 oh-my-posh 安装字体
oh-my-posh font install
 
# 或手动安装推荐字体
# - Cascadia Code Nerd Font
# - FiraCode Nerd Font
# - JetBrains Mono Nerd Font

配置 Windows Terminal 字体

  1. 打开 Windows Terminal 设置(Ctrl + ,
  2. 选择配置文件 → 外观
  3. 字体选择已安装的 Nerd 字体

0x04、配置 PowerShell

编辑 PowerShell 配置文件:

# 打开配置文件
notepad $PROFILE

添加以下内容:

# 初始化 oh-my-posh
oh-my-posh init pwsh | Invoke-Expression
 
# 或指定主题
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression

0x05、常用主题推荐

查看所有主题

# 列出所有主题
Get-ChildItem -Path "$env:POSH_THEMES_PATH\*" | Select-Object Name
 
# 主题预览
oh-my-posh config export image --config "$env:POSH_THEMES_PATH\主题名.omp.json"

推荐主题

主题特点适用场景
paradox信息丰富,Git 友好日常开发
agnoster简洁美观通用
powerlevel10k_lean极简风格追求简洁
tokyo东京夜色风格视觉美观
jandedobbeleer作者主题功能全面
kushalGit 状态详细Git 重度用户

设置主题

# 方法1:在 $PROFILE 中指定
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression
 
# 方法2:使用环境变量
$env:POSH_THEME = "$env:POSH_THEMES_PATH\paradox.omp.json"
oh-my-posh init pwsh | Invoke-Expression

0x06、自定义主题

创建自定义主题

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "segments": [
        {
          "type": "path",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background": "#007acc",
          "properties": {
            "style": "full"
          }
        },
        {
          "type": "git",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#193549",
          "background": "#fffb38",
          "properties": {
            "branch_icon": "\ue0a0 "
          }
        }
      ]
    }
  ]
}

常用配置项

{
  "segments": [
    {
      "type": "path",           // 路径显示
      "type": "git",            // Git 状态
      "type": "node",           // Node.js 版本
      "type": "python",         // Python 版本
      "type": "go",             // Go 版本
      "type": "executiontime",  // 命令执行时间
      "type": "time"            // 时间显示
    }
  ]
}

0x07、完整配置示例

# $PROFILE 内容
 
# 设置编码
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
 
# 初始化 oh-my-posh
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression
 
# 设置别名
Set-Alias -Name ll -Value Get-ChildItem
Set-Alias -Name which -Value Get-Command
 
# 自定义函数
function .. { Set-Location .. }
function ... { Set-Location ..\.. }
function ~ { Set-Location $HOME }
 
# 自动补全
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -EditMode Windows

0x08、参考链接


更新时间: 2026-03-27