Windows Terminal中Powershell的oh-my-posh配置失效,仅显示PS>
Oh My Posh 在PowerShell 7.4中配置失效问题
问题概述
- 新电脑已安装PowerShell v7.4,从配置正常的旧电脑复制了Oh My Posh相关配置,但新终端仅显示默认
PS>提示符 - 手动执行初始化命令
oh-my-posh --init --shell pwsh --config "C:\dropbox\oh-my-posh\themes\cobalt2.omp.json" | Invoke-Expression后,格式化后的路径会短暂显示,随即恢复为默认PS> - 已同步旧电脑的Windows Terminal配置,问题仍未解决
配置文件详情
PowerShell Profile(执行code $PROFILE打开)
oh-my-posh --init --shell pwsh --config "C:\dropbox\oh-my-posh\themes\mytheme.omp.json" | Invoke-Expression Import-Module -Name Terminal-Icons $env:POSH_GIT_ENABLED = $true
自定义主题文件(mytheme.omp.json)
{ "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", "blocks": [ { "alignment": "left", "segments": [ { "background": "#1478DB", "foreground": "#000000", "leading_diamond": "\ue0b6", "trailing_diamond": "\uE0B0", "properties": { "style": "full" }, "style": "diamond", "template": "{{ .Path }} ", "type": "path" }, { "background": "#3AD900", "background_templates": [ "{{ if or (.Working.Changed) (.Staging.Changed) }}#FFC600{{ end }}", "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#FFCC80{{ end }}", "{{ if gt .Ahead 0 }}#B388FF{{ end }}", "{{ if gt .Behind 0 }}#B388FF{{ end }}" ], "foreground": "#000000", "leading_diamond": "<transparent,background>\uE0B0</>", "trailing_diamond": "\ue0b4", "properties": { "fetch_stash_count": true, "fetch_status": true }, "style": "diamond", "template": " {{ .HEAD }}{{ if .Staging.Changed }}<#FF6F00> \uf046 {{ .Staging.String }}</>{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ", "type": "git" } ], "type": "prompt" } ], "final_space": true, "version": 2 }
更新内容
按照@mklement0的调试指引操作后出现报错,寻求相关解决办法
内容的提问来源于stack exchange,提问作者Mark Cooper
相关产品推荐
相关产品推荐

