dahlbyk / posh-git

A PowerShell environment for Git
http://dahlbyk.github.io/posh-git/
MIT License
7.62k stars 802 forks source link

VSCode shell integration disables posh-git prompt #931

Open Jawz84 opened 1 year ago

Jawz84 commented 1 year ago

System Details

Issue Description

I am experiencing a problem with VSCode Terminal Shell Integration, the new feature that shows color coded dots in the margin for successfull/failed command executions. Read more here. It prevents the prompt from being adapted by Posh-Git. So on loading of Posh-Git, the prompt stays the same. (posh-git does load, and stuff like branch name completion does work, it's just the apdaptation of the prompt function that fails.)

I realize this is not a problem of Posh-Git per se. I just wanted to make you aware of this.

Work-around

I found a work-around by setting terminal.integrated.shellIntegration.enabled to false, and restarting the terminal.

Remarks

What is maybe interesting, is that you can see the injected script that VSCode uses for the decorations etc by running code (code --locate-shell-integration-path pwsh). I wouldn't know how to adapt that so that it displays posh-git prompt style too.

dahlbyk commented 1 year ago

Try swapping Import-Module posh-git after what VS Code injects. Does posh-git prompt win, but the VS Code feature breaks?

Looks like there are custom escape sequences, which could either be customized or built into posh-git.

pavel-zhigulin commented 1 year ago

I have the same problem. Even when import posh-git after loading of the terminal, there is no posh-git prompt available in terminal.

Thanks for the workaround. It works!

0ryant commented 9 months ago

thanks for the workaround :)

martixy commented 4 months ago

This might be unrelated to OP, but I landed here having posh-git in ~\Documents\PowerShell\Modules\posh-git\1.1.0 and wondering why it's not showing up in my PS7/vscode shell, and so others will probably arrive here for the same reasons. For those people:

Each shell is its own environment.

For each shell you want posh-git in, run PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force and Add-PoshGitToProfile

dahlbyk commented 4 months ago

For each shell you want posh-git in, run PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force and Add-PoshGitToProfile

Install-Module installs to a different location for Windows PowerShell and PowerShell Core, but once installed for both you shouldn't need to reinstall.

Instead of installing for each shell you can also try Add-PoshGitToProfile -AllHosts, which should be run for the default host, VS Code host, etc.