Reputation: 11
When I open a GitBash terminal in VSCode while I have a virtual environment activated, the path displayed on top of the input line is C:/Users/username/AppData/Local/Programs/Microsoft VS Code, but the current working directory is the root of the current project (which is what I want), as proved by running pwd or ls, or cd'ing into a subfolder.
Cd'ing into a subfolder and then back into the parent, or running exec bash fixes the problem, until I open the project again. Also, the problem only happens with GitBash, while powershell works fine.
I have tried inspecting activate.ps1 and activate.bat in my venv/Scripts folder and the .bashrc file, but there is no line like export PS1="(venv) $PS1", nor any reference to the VSCode installation folder. I have also tried changing "terminal.integrated.cwd" to "${workspaceFolder}" in VSCode's settings.json, but to no avail. I suppose it's a bug in how GitBash initializes or updates the displayed path, but I can't for the life of me figure out what it is precisely.
Thanks in advance.
Upvotes: 1
Views: 127
Reputation: 11
I encountered the same problem today and was also not able to fix it. Below are some workarounds I tried and a few thoughts on what/where the problem might be.
If I look at my $PS1
, it looks like this:
$ echo $PS1
\[\](animations) \[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ \[\]
As you can see it uses $PWD
to include the current path and $PWD
is set to:
$ echo $PWD
C:/Users/<my name>/AppData/Local/Programs/Microsoft VS Code
This explains why cd'ing out and into the folder fixes the problem, since the shell then updates $PWD
.
I tried multiple workarounds (beside the things that you already tried), but they all did not help:
cd "$(pwd)"
to the end of .bashrc
PWD="$(pwd)"
to the end of .bashrc
"terminal.integrated.env.windows": {
"PWD": "${workspaceFolder}"
}
3.
but with using a hard-coded path instead of ${workspaceFolder}
Since workaround 1.
and 2.
fail, I guess that either VSCode or the Python extension sets the $PWD
variable after the shell reads in the files. Furthermore, since 3.
and 4.
also do not work, I would narrow it down to the Python extension.
Upvotes: 1