如何在 oh-my-posh 中显示 Python 的当前虚拟环境?

5
首先,我正在使用 Oh My Posh 中的 hotstick.minimal 主题,效果如下图所示。 enter image description here 如您所见,当前的虚拟环境显示效果不好。我在 JSON 文件中进行了一些更改,然后显示效果变成了这样。 enter image description here 我不想在左侧显示虚拟环境的名称。应该怎么做?
以下是我的 JSON 文件:
{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "final_space": true,
  "osc99": true,
  "console_title": true,
  "console_title_style": "template",
  "console_title_template": "{{.Folder}}{{if .Root}} :: root{{end}} :: {{.Shell}}",
  "blocks": [

    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        { 
          "type": "root",
          "style": "plain",
          "foreground": "yellow",
          "properties": {
            "root_icon": ""
          }
        },
        {
          "type": "path",
          "style": "powerline",
          "foreground": "black",
          "background": "#68D6D6",
      "powerline_symbol": "",
          "leading_diamond": "",
          "trailing_diamond": "",
          "properties": {
        "prefix": " \uF07C ",
            "style": "folder"
          }
        },
        {
          "type": "python",
          "style": "powerline",
          "powerline_symbol": "\uE0B0",
          "foreground": "#100e23",
          "background": "#906cff",
          "properties": {
            "prefix": " \uE235 "
          }
        },
        {
          "type": "git",
          "style": "powerline",
          "powerline_symbol": "",
          "foreground": "black",
          "background": "green",
          "properties": {
            "display_stash_count": true,
            "display_upstream_icon": true,
            "display_status": true,
            "display_status_detail": true,
            "branch_icon": "  ",
            "branch_identical_icon": "≡",
            "branch_ahead_icon": "↑",
            "branch_behind_icon": "↓",
            "branch_gone": "≢",
            "local_working_icon": "",
            "local_staged_icon": "",
            "stash_count_icon": "",
            "commit_icon": "▷ ",
            "tag_icon": "▶ ",
            "rebase_icon": "Ɫ ",
            "cherry_pick_icon": "✓ ",
            "merge_icon": "◴ ",
            "no_commits_icon": "[no commits]",
            "status_separator_icon": " │",
            "status_colors_enabled": true,
            "color_background": true,
            "local_changes_color": "yellow"
          }
        }
      ]
    }
  ]
}

注意:由于字体的原因,有些符号可能无法显示。

2个回答

8

你需要在你的$PROFILE (profile.ps1)中包含以下内容:

$env:VIRTUAL_ENV_DISABLE_PROMPT = 1

注意事项:

  1. 首先停用虚拟环境(venv)
  2. 为了使其生效,请关闭并重新打开终端。

在此处查看更详细的讨论:https://github.com/JanDeDobbeleer/oh-my-posh/discussions/390


0

我有同样的问题,但在我的情况下,workon env不起作用。我不知道这些对你是否有效,但是运行以下命令可以解决问题。

Set-ExecutionPolicy Unrestricted -Force

在 PowerShell 中以 管理员身份 运行


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