Open jingjingan opened 2 weeks ago
That prompt is set via the PS1
shell variable, specifically via \w
. Here is the Bash code that handles it.
One curious thing about this is that it looks at the PWD
shell variable and it only calls getcwd()
instead if `PWD is not set.
Can you verify via env | grep -i pwd
that you have only one such variable? (I could imagine that there is a PWD
one and a pwd
one.)
If that is not the case, could you see whether there is another shell variable that contains that path, e.g. via `env | grep '=C:.*Microsoft.VS.Code$'?
Please see my reply below. About this issue ,no matter how I set terminal cwd in vs code, git bash behaves same.
$ env | grep '=C:.*Microsoft.VS.Code$'
PWD=C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code
(.venv)
hola_@DESKTOP-JO4V5P1 MINGW64 C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code (main)
$ env | grep -i pwd
PWD=C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code
PS1=\[\](.venv) \[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ \[\]
(.venv)
hola_@DESKTOP-JO4V5P1 MINGW64 C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code (main)
$ pwd
/d/ICCLOUDY/12客户/工具/py-stat
(.venv)
That's bizarre. What does env | grep py-stat
show?
$ env | grep py-stat
VIRTUAL_ENV=D:/ICCLOUDY/12客户/工具/py-stat/.venv
VIRTUAL_ENV=D:/ICCLOUDY/12客户/工具/py-stat/.venv
PATH=c:\Users\hola_\.vscodetensions\ms-python.python-2024.12.3-win32-x64\python_files\deactivatash;D:\ICCLOUDY\12客户\工具\py-stat\.venv\Scripts;C:\Program Files\Git\mingw6in;C:\Program Files\Git\usin;C:\Users\holain;C:\Program Files\OpenSSH;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell
1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git/c/Users/hola_/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Us 1.0;C:\WINDOW
S\System32\OpenSSH;C:\Program Files\Git/c/Users/hola_/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Users/hola_/.vscode/extensions/ms-python.python-2024.12.3-win32-x64/python_files/deactivate/bash:/d/ICCLOUDY/12客户/工具/py-stat/.venv/Scripts:/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Program Files/OpenSSH:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Gradle/gradle-7.5.1/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Java/jdk1.8.0_231/bin:/c/Program Files (x86)/GBESClient/GBESClient:/c/Users/hola_/AppData/Local/Programs/Python/Python312/Scripts:/c/Users/hola_/AppData/Local/Programs/Python/Python312:/c/Users/hola_/AppData/Local/Microsoft/WindowsApps:/c/Users/hola_/AppData/Local/Programs/Microsoft VS Code/bin:/c/Program Files/OpenSSH:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Gradle/gradle-7.5.1/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Java/jdk1.8.0_231/bin:/c/Program Files (x86)/GBESClient/GBESClient:/c/Users/hola_/AppData/Local/Programs/Python/Python312/Scripts:/c/Users/hola_/AppData/Local/Programs/Python/Python312:/c/Users/hola_/AppData/Local/Microsoft/WindowsApps:/c/Users/hola_/AppData/Local/Programs/Microsoft VS Code/bin:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/hola_/.ssh/scripts
ORIGINAL_PATH=/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Users/hola_/.vscode/extensions/ms-python.python-2024.12.3-win32-x64/python_files/deactivate/bash:/d/ICCLOUDY/12客户/工具/py-stat/.venv/Scripts:/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Program Files/OpenSSH:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Gradle/gradle-7.5.1/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Java/jdk1.8.0_231/bin:/c/Program Files (x86)/GBESClient/GBESClient:/c/Users/hola_/AppData/Local/Programs/Python/Python312/Scripts:/c/Users/hola_/AppData/Local/Programs/Python/Python312:/c/Users/hola_/AppData/Local/Microsoft/WindowsApps:/c/Users/hola_/AppData/Local/Programs/Microsoft VS Code/bin:/c/Program Files/OpenSSH:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Gradle/gradle-7.5.1/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Java/jdk1.8.0_231/bin:/c/Program Files (x86)/GBESClient/GBESClient:/c/Users/hola_/AppData/Local/Programs/Python/Python312/Scripts:/c/Users/hola_/AppData/Local/Programs/Python/Python312:/c/Users/hola_/AppData/Local/Microsoft/WindowsApps:/c/Users/hola_/AppData/Local/Programs/Microsoft VS Code/bin
(.venv)
And what does realpath "$PWD" "$(pwd)"
report?
VIRTUAL_ENV=D:/ICCLOUDY/12客户/工具/py-stat/.venv VIRTUAL_ENV=D:/ICCLOUDY/12客户/工具/py-stat/.venv
This is quite strange, by the way. Does VIRTUAL_ENV
contain multi-line text?
PATH=c:\Users\hola_\.vscodetensions\ms-python.python-2024.12.3-win32-x64\python_files\deactivatash;D:\ICCLOUDY\12客户\工具\py-stat\.venv\Scripts;C:\Program Files\Git\mingw6in;C:\Program Files\Git\usin;C:\Users\holain;C:\Program Files\OpenSSH;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell 1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git/c/Users/hola_/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Us 1.0;C:\WINDOW S\System32\OpenSSH;C:\Program Files\Git/c/Users/hola_/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Users/hola_/.vscode/extensions/ms-python.python-2024.12.3-win32-x64/python_files/deactivate/bash:/d/ICCLOUDY/12客户/工具/py-stat/.venv/Scripts:/mingw64/bin:/usr/bin:/c/Users/hola_/bin:/c/Program Files/OpenSSH:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Gradle/gradle-7.5.1/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Java/jdk1.8.0_231/bin:/c/Program Files (x86)/GBESClient/GBESClient:/c/Users/hola_/AppData/Local/Programs/Python/Python312/Scripts:/c/Users/hola_/AppData/Local/Programs/Python/Python312:/c/Users/hola_/AppData/Local/Microsoft/WindowsApps:/c/Users/hola_/AppData/Local/Programs/Microsoft VS Code/bin:/c/Program Files/OpenSSH:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/cmd:/c/Gradle/gradle-7.5.1/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Java/jdk1.8.0_231/bin:/c/Program Files (x86)/GBESClient/GBESClient:/c/Users/hola_/AppData/Local/Programs/Python/Python312/Scripts:/c/Users/hola_/AppData/Local/Programs/Python/Python312:/c/Users/hola_/AppData/Local/Microsoft/WindowsApps:/c/Users/hola_/AppData/Local/Programs/Microsoft VS Code/bin:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/hola_/.ssh/scripts
And this is actively wrong. The first part of the PATH
variable contains a Windows-style path list, with absolute Windows paths containing drive prefixes that are separated by ;
. The second part is as expected: a Unix-style path list, with absolute Unix paths starting with /
and separated by :
.
I suspect that this is venv
's doing, which may be lacking support for running in a Git Bash, assuming instead that it either runs on Linux/macOS/Unix in a Unix shell or on Windows in CMD/PowerShell, but not in the MSYS2 Bash that sort of emulates Unix paths but that emulation obviously cannot extend to the native Windows variant of Python.
$(pwd)
hola_@DESKTOP-JO4V5P1 MINGW64 C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code (main) $ echo $PWD C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code (.venv) hola_@DESKTOP-JO4V5P1 MINGW64 C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code (main) $ echo $(pwd) /d/ICCLOUDY/12客户/工具/py-stat (.venv)
Does VIRTUAL_ENV contain multi-line text?
no
I checked the python add-on repo, there is a same issue reported.
I did not realize that this could be the add-on issue...
I checked the python add-on repo, there is a same issue reported.
Could you please provide the link?
And what does
realpath "$PWD" "$(pwd)"
report?
And could you please run this realpath
command?
$ realpath "$PWD" "$(pwd)"
C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code
/d/ICCLOUDY/12客户/工具/py-stat
(.venv)
add-on issue link: https://github.com/microsoft/vscode-python/issues/23382
Does $PWD
still show the incorrect value after a cd "$(pwd)"
?
After a cd "$(pwd)", $PWD corrected.
hola_@DESKTOP-JO4V5P1 MINGW64 C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code (main)
$ realpath "$PWD" "$(pwd)"
C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code
/d/ICCLOUDY/12客户/工具/py-stat
(.venv)
hola_@DESKTOP-JO4V5P1 MINGW64 C:/Users/hola_/AppData/Local/Programs/Microsoft VS Code (main)
$ cd "$(pwd)"
(.venv)
hola_@DESKTOP-JO4V5P1 MINGW64 /d/ICCLOUDY/12客户/工具/py-stat (main)
$ realpath "$PWD" "$(pwd)"
/d/ICCLOUDY/12客户/工具/py-stat
/d/ICCLOUDY/12客户/工具/py-stat
(.venv)
Setup
insert your response here
Details
run integrated git bash in visual studio code. I have checked all vistual studio related setting, all good. this issue only happens while I open a python proejct in visual studio code , and then open git bash in vs code. visual studio code version: 版本: 1.92.2 (user setup) 提交: fee1edb8d6d72a0ddff41e5f71a671c23ed924b9 日期: 2024-08-14T17:29:30.058Z Electron: 30.1.2 ElectronBuildId: 9870757 Chromium: 124.0.6367.243 Node.js: 20.14.0 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.19045
the command line prompt shows the correct dir name.
the command line prompt shows the wrong dir name.
no .