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

Meh*_*göz 6 python powershell virtualenv powerline oh-my-posh

首先,我在 oh my posh 中使用 hotstick.minimal 主题。它看起来像这样。在此输入图像描述

\n

正如您所看到的,当前的 venv 看起来不太好。我对 JSON 文件做了一些更改。然后看起来像这样。

\n

在此输入图像描述

\n

我不想在左侧显示 venv 的名称。我怎样才能做到这一点?

\n

这是我的 JSON 文件:

\n
{\n  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",\n  "final_space": true,\n  "osc99": true,\n  "console_title": true,\n  "console_title_style": "template",\n  "console_title_template": "{{.Folder}}{{if .Root}} :: root{{end}} :: {{.Shell}}",\n  "blocks": [\n\n    {\n      "type": "prompt",\n      "alignment": "left",\n      "segments": [\n        { \n          "type": "root",\n          "style": "plain",\n          "foreground": "yellow",\n          "properties": {\n            "root_icon": "\xee\x82\xa2"\n          }\n        },\n        {\n          "type": "path",\n          "style": "powerline",\n          "foreground": "black",\n          "background": "#68D6D6",\n      "powerline_symbol": "\xee\x82\xb0",\n          "leading_diamond": "\xee\x82\xb0",\n          "trailing_diamond": "\xee\x82\xb0",\n          "properties": {\n        "prefix": " \\uF07C ",\n            "style": "folder"\n          }\n        },\n        {\n          "type": "python",\n          "style": "powerline",\n          "powerline_symbol": "\\uE0B0",\n          "foreground": "#100e23",\n          "background": "#906cff",\n          "properties": {\n            "prefix": " \\uE235 "\n          }\n        },\n        {\n          "type": "git",\n          "style": "powerline",\n          "powerline_symbol": "\xee\x82\xb0",\n          "foreground": "black",\n          "background": "green",\n          "properties": {\n            "display_stash_count": true,\n            "display_upstream_icon": true,\n            "display_status": true,\n            "display_status_detail": true,\n            "branch_icon": " \xee\x82\xa0 ",\n            "branch_identical_icon": "\xe2\x89\xa1",\n            "branch_ahead_icon": "\xe2\x86\x91",\n            "branch_behind_icon": "\xe2\x86\x93",\n            "branch_gone": "\xe2\x89\xa2",\n            "local_working_icon": "",\n            "local_staged_icon": "",\n            "stash_count_icon": "",\n            "commit_icon": "\xe2\x96\xb7 ",\n            "tag_icon": "\xe2\x96\xb6 ",\n            "rebase_icon": "\xe2\xb1\xa2 ",\n            "cherry_pick_icon": "\xe2\x9c\x93 ",\n            "merge_icon": "\xe2\x97\xb4 ",\n            "no_commits_icon": "[no commits]",\n            "status_separator_icon": " \xe2\x94\x82",\n            "status_colors_enabled": true,\n            "color_background": true,\n            "local_changes_color": "yellow"\n          }\n        }\n      ]\n    }\n  ]\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

注意:由于字体的原因,某些符号可能不会显示。

\n

小智 9

您必须在 $PROFILE ( profile.ps1) 中包含以下内容:

$env:VIRTUAL_ENV_DISABLE_PROMPT = 1
Run Code Online (Sandbox Code Playgroud)

两个注意事项:

  1. 首先停用 venv
  2. 关闭并重新打开终端以使其正常工作。

在这里查看更全面的讨论:https://github.com/JanDeDobbeleer/oh-my-posh/discussions/390