主要是整理下在用的配置备忘,官方网站:https://ohmyposh.dev/docs/installation/windows
安装及更新
winget install JanDeDobbeleer.OhMyPosh --source winget
winget upgrade JanDeDobbeleer.OhMyPosh --source winget
配置文件
PowerShell 7
路径: C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
oh-my-posh init pwsh --config ~/json.omp.json | Invoke-Expression
PowerShell 5.x
路径: C:\Users\<user>\Documents\WindowsPowerShell\profile.ps1
oh-my-posh init powershell --config ~/json.omp.json | Invoke-Expression
顺便记录乱码解决
主要表现就是在 powershell 里调用其它命令出现乱码,只需要在上面的两个配置文件中添加
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
json.omp.json
路径:C:\Users\<user>\json.omp.json
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"background": "#003543",
"foreground": "#ffffff",
"style": "plain",
"template": " \ue641 {{ .CurrentDate | date .Format }} ",
"type": "time"
},
{
"background": "#61AFEF",
"foreground": "#ffffff",
"style": "diamond",
"template": "{{if .Root}} \uf0e7 {{.UserName}} {{else}} {{.UserName}} {{end}}",
"trailing_diamond": "\ue0b0",
"type": "session"
},
{
"background": "#C678DD",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"options": {
"folder_icon": "\uf115",
"folder_separator_icon": " \ue0b1 ",
"max_depth": 2,
"style": "agnoster_short"
},
"style": "powerline",
"template": " {{ .Path }} ",
"type": "path"
},
{
"background": "#95ffa4",
"foreground": "#193549",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " {{ .HEAD }} ",
"type": "git"
}
],
"type": "prompt"
}
],
"console_title_template": "{{if .Root}} \u26a1 {{end}}{{.UserName}} \u2794 {{.Folder}}",
"final_space": true,
"version": 4
}
字体设置
如果按上面的设置完有些图标或者字符出现方块或乱码那么就需要额外设置字体,在 pwsh 界面下输入 ctrl + shift + , 打开设置在 "profiles" -> "defaults" 节点下添加
{
"font":
{
"face": "FiraMono Nerd Font"
}
}
扩展集成:Claude Code 状态栏
配置路径: C:\Users\<user>\.claude\settings.json 或者添加到 cc-switch 中
{
"statusLine": {
"command": "oh-my-posh claude",
"padding": 0,
"type": "command"
}
}
发表回复