[Python] VS Code Python extension injects incorrect start up script oh-my-posh variables with...

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    The task


    I'm using oh-my-posh to display extra info in the terminal for PowerShell (v7) and Git Bash.

    The problem


    When using Windows Terminal I can see that the theme changes are present, but in the VS Code integrated terminal the changes are not reflected for Git Bash (there are no issues with PowerShell): the previous theme (which was a downloaded local JSON) is still present. Moreover, the previous theme had a segment on the right saying CONFIG ERROR. Additionally, this is only the case when opening a project folder, as VS Code instances outside of a project don't have the issue. I am using poetry and working on a python project, if this is of any importance.

    Debug


    Here is my current .bashrc:

    eval "$(oh-my-posh init bash --config 'https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/atomic.omp.json')"


    Here is the .bash_profile:

    test -f ~/.profile && . ~/.profile
    test -f ~/.bashrc && . ~/.bashrc


    Here is the head (up to the ERROR statement) of the oh-my-posh debug output (note that although a (Git) Bash terminal is selected in VS Code it thinks it is PowerShell, which helps to explain the mangled paths):

    Version: 26.14.3

    Shell: pwsh (7.5.2)

    Prompt:

     BB   test   main ≡    CONFIG ERROR   in pwsh at 11:32:18

    Segments:

    ConsoleTitle(true) - 0 ms
    Session(true) - 0 ms
    Path(true) - 1 ms
    Git(true) - 27 ms
    Root(true) - 0 ms
    Status(true) - 1 ms
    Node(false) - 0 ms
    Go(false) - 0 ms
    Python(true) - 0 ms
    Shell(true) - 0 ms
    Time(true) - 0 ms

    Run duration: 31.6562ms

    Cache path: C:\Users\BB\AppData\Local\oh-my-posh

    Config path: C:\Users\BB\AppData\Local\Programs\oh-my-posh hemestomic.omp.json

    Logs:

    [DEBUG] 11:32:18.499 debug.go:35 → logging enabled, raw mode: false
    [DEBUG] 11:32:18.499 load.go:filePath:102 → config set using POSH_THEME: C:\Users\BB\AppData\Local\Programs\oh-my-posh hemestomic.omp.json
    [TRACE] 11:32:18.499 load.go:filePath() - 0s
    [ERROR] 11:32:18.500 load.go:readConfig:156 → open C:\Users\BB\AppData\Local\Programs\oh-my-posh hemestomic.omp.json: The filename, directory name, or volume label syntax is incorrect.


    In VS Code clicking the 'Show Environment Contributions' opens a markdown that points where the issue likely is (note only the python extension variables are shown):

    # Terminal Environment Changes

    ## Extension: ms-python.python

    Activated environment for `~\AppData\Local\pypoetry\Cache\virtualenvs\test-1xIxFAGP-py3.13\Scripts\python.exe`

    - `PYTHON_BASIC_REPL=1`
    - `CONDA_PROMPT_MODIFIER=False`
    - `PATH=c:\Users\BB\.vscode\extensions\ms-python.python-2025.10.0-win32-x64\python_files\deactivate\powershell;C:\Users\BB\AppData\Local\pypoetry\Cache\virtualenvs\test-1xIxFAGP-py3.13/Scripts;C:\Program Files\PowerShell\7;${env:pATH}`
    - `PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW;.CPL`
    - `POSH_SESSION_ID=96cd2964-5ed9-4dac-8f2e-9b90fdc4bfd8`
    - `POSH_SHELL=pwsh`
    - `POSH_SHELL_VERSION=7.5.2`
    - `POSH_THEME=C:\Users\BB\AppData\Local\Programs\oh-my-posh\themes\atomic.omp.json`
    - `POWERLINE_COMMAND=oh-my-posh`
    - `PSMODULEPATH=C:\Users\BB\OneDrive\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules`
    - `PYENV_VIRTUALENV_DISABLE_PROMPT=1`
    - `PYTHONIOENCODING=utf-8`
    - `PYTHONUNBUFFERED=1`
    - `VIRTUAL_ENV=C:\Users\BB\AppData\Local\pypoetry\Cache\virtualenvs\test-1xIxFAGP-py3.13`
    - `VIRTUAL_ENV_DISABLE_PROMPT=1`
    - `VIRTUAL_ENV_PROMPT=test-py3.13`


    In the location C:\Users\BB\AppData\Local\oh-my-posh, there is a Shell Script which contains oh-my-posh variables (note only the top of the file is listed below):

    export POSH_THEME=$'C:\\Users\\BB\\AppData\\Local\\Programs\\oh-my-posh\\themes\\atomic.omp.json'
    export POSH_SHELL='bash'
    export POSH_SHELL_VERSION=$BASH_VERSION
    export POWERLINE_COMMAND='oh-my-posh'
    export CONDA_PROMPT_MODIFIER=false
    export OSTYPE=$OSTYPE

    # disable all known python virtual environment prompts
    export VIRTUAL_ENV_DISABLE_PROMPT=1
    export PYENV_VIRTUALENV_DISABLE_PROMPT=1

    # global variables
    _omp_start_time=''
    _omp_stack_count=0
    _omp_execution_time=-1
    _omp_no_status=true
    _omp_status=0
    _omp_pipestatus=0
    _omp_executable=$'C:/Users/BB/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe'

    export POSH_SESSION_ID=$("$_omp_executable" get uuid)

    # switches to enable/disable features
    _omp_cursor_positioning=0
    _omp_ftcs_marks=0


    Lastly, changing the VS Code settings.json option: "terminal.integrated.shellIntegration.enabled" from the default true to false resolves the problem, but at the expense of loosing the additional features that it provides. Note that I have installed and set in VS Code settings.json a Monospaced Nerd Font.

    Conclusions


    It seems that the VS Code python extension is injecting oh-my-posh variables in the shell; why on earth, I don't know. But critically they are wrong, since it is a bash shell not pwsh.

    1. What is at fault, is it oh-my-posh, VS Code, poetry, or something else?
    2. How do I fix the issue? (I'm not interested in simply disabling shell integrations alltogether).

    Continue reading...

Compartilhe esta Página