Windows Terminal + oh-my-posh不能显示git状态。

8
我在Windows终端中安装了oh-my-posh和posh-git,但它无法跟踪任何git更改,如您在图片中所见。无论我做了什么更改,它都只是显示为没有状态:

enter image description here

我也尝试过不使用 posh-git,因为我以为 oh-my-posh 默认就具备这个功能,但结果仍然相同。

这是我的 oh-my-posh 主题:

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "segments": [
        {
          "background": "#91ddff",
          "foreground": "#100e23",
          "powerline_symbol": "",
          "properties": {
            "folder_icon": "",
            "folder_separator_icon": "  ",
            "home_icon": "",
            "style": "agnoster"
          },
          "style": "powerline",
          "type": "path"
        },
        {
          "background": "#95ffa4",
          "foreground": "#193549",
          "powerline_symbol": "",
          "style": "powerline",
          "type": "git"
        },
        {
          "background": "#906cff",
          "foreground": "#100e23",
          "powerline_symbol": "",
          "properties": {
            "prefix": "  "
          },
          "style": "powerline",
          "type": "python"
        },
        {
          "background": "#ff8080",
          "foreground": "#ffffff",
          "powerline_symbol": "",
          "style": "powerline",
          "type": "exit"
        }
      ],
      "type": "prompt"
    }
  ],
  "final_space": true
}


2
你安装了Git吗? - phuzi
@phuzi 谢谢伙计!我刚刚退出格式化,还没有安装git。 - Menelaos Vergis
1个回答

7

在这里找到了答案: https://ohmyposh.dev/docs/git/。 显然,默认情况下是禁用 git status 命令的,因此您需要将一个属性部分添加到 git 配置中:

{
  "type": "git",
  "style": "powerline",
  "powerline_symbol": "\uE0B0",
  "foreground": "#193549",
  "background": "#ffeb3b",
  "properties": {
    "display_status": true,
    "display_stash_count": true,
    "display_upstream_icon": true
  }
}

可以使用 posh-git 进行操作:

{
  "type": "poshgit",
  "style": "powerline",
  "powerline_symbol": "\uE0B0",
  "foreground": "#ffffff",
  "background": "#0077c2"
}

奇怪,我不需要进行任何配置更改! - phuzi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接