"Open in Terminal" with git bash as default breaks tilde expansion #18210

Open
opened 2026-01-31 06:06:59 +00:00 by claunia · 7 comments
Owner

Originally created by @MGraefe on GitHub (Aug 19, 2022).

I am not really sure if this is a problem of the git bash or Windows Terminal, but here we go:

  • I have the git bash loaded into windows terminal with this configuration:
    {
        "commandline": "\"C:/Program Files/Git/bin/bash.exe\" --login -i",
        "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
        "hidden": false,
        "name": "Git Bash",
        "source": "Git",
        "startingDirectory": "%USERPROFILE%"
    },
    
    This profile is selected as my default, i.e. "defaultProfile": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}", is set.
  • When I launch Windows Terminal from the task-bar everything works fine, e.g. my default path is shown as ~ and things like cd ~ work as well. Everything behaves as expected.
  • However when I launch Windows Terminal via right-click in explorer and "Open in Terminal", any tilde completion is broken. cd ~ produces the error bash: cd: /%HOMEDRIVE%%HOMEPATH%: No such file or directory and I can't use ~ in any command really.
    • I believe this is a problem with the integration into Windows Terminal, as using Git bash here from the explorer context menu opens a shell in which cd ~ works without problems.

Versions:

  • Windows Terminal 1.14.2281.0 on Windows 10.
  • Git version 2.37.2 (the official release from git-scm.com)
Originally created by @MGraefe on GitHub (Aug 19, 2022). I am not really sure if this is a problem of the git bash or Windows Terminal, but here we go: * I have the git bash loaded into windows terminal with this configuration: ```json { "commandline": "\"C:/Program Files/Git/bin/bash.exe\" --login -i", "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}", "hidden": false, "name": "Git Bash", "source": "Git", "startingDirectory": "%USERPROFILE%" }, ``` This profile is selected as my default, i.e. `"defaultProfile": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",` is set. * When I launch Windows Terminal from the task-bar everything works fine, e.g. my default path is shown as `~` and things like `cd ~` work as well. Everything behaves as expected. * However when I launch Windows Terminal via right-click in explorer and "Open in Terminal", any tilde completion is broken. `cd ~` produces the error `bash: cd: /%HOMEDRIVE%%HOMEPATH%: No such file or directory` and I can't use `~` in any command really. * I believe this is a problem with the integration into Windows Terminal, as using `Git bash here` from the explorer context menu opens a shell in which `cd ~` works without problems. Versions: * Windows Terminal 1.14.2281.0 on Windows 10. * Git version 2.37.2 (the official release from git-scm.com)
claunia added the Issue-BugNeeds-Tag-FixProduct-TerminalCulprit-Centennial labels 2026-01-31 06:07:00 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Aug 19, 2022):

Does opening Terminal from the explorer address bar repro the same behavior? (wt -d . to open up in the same CWD)

What do the environment variables look like when:

  • Terminal is launched via the context menu into git bash
  • Terminal is launched via the start menu / taskbar into git bash
  • Terminal is launched via the context menu into CMD (i.e. change the default profile to command prompt)
  • Terminal is launched via the start menu / taskbar into CMD

I know that's a lot, but I'm just looking for anything that's different here, maybe some smoking gun that some env var didn't propogate

@zadjii-msft commented on GitHub (Aug 19, 2022): Does opening Terminal from the explorer address bar repro the same behavior? (`wt -d .` to open up in the same CWD) What do the environment variables look like when: * Terminal is launched via the context menu into git bash * Terminal is launched via the start menu / taskbar into git bash * Terminal is launched via the context menu into CMD (i.e. change the default profile to command prompt) * Terminal is launched via the start menu / taskbar into CMD I know that's a lot, but I'm just looking for anything that's different here, maybe some smoking gun that some env var didn't propogate
Author
Owner

@ghost commented on GitHub (Aug 23, 2022):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Aug 23, 2022): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@MGraefe commented on GitHub (Aug 24, 2022):

Hi, sorry for the delayed feedback.

  • Putting wt -d . into the explorer address bar shows the correct behavior, tilde expansion works.
  • Environment variables seem okay, even in the case where tilde expansion is not working:
    BOB@MYPC MINGW64 /c
    $ cd ~
    bash: cd: /c/%HOMEDRIVE%%HOMEPATH%: No such file or directory
    
    BOB@MYPC MINGW64 /c
    $ echo $HOMEDRIVE $HOMEPATH
    C: \Users\Bob
    

I am not sure what other environment variables you're interested in. The problem seems to be that bash gets fed the unexpanded cmd-like %HOMEDRIVE% and %HOMEPATH% paths.

@MGraefe commented on GitHub (Aug 24, 2022): Hi, sorry for the delayed feedback. * Putting `wt -d .` into the explorer address bar shows the correct behavior, tilde expansion works. * Environment variables seem okay, even in the case where tilde expansion is not working: ``` BOB@MYPC MINGW64 /c $ cd ~ bash: cd: /c/%HOMEDRIVE%%HOMEPATH%: No such file or directory BOB@MYPC MINGW64 /c $ echo $HOMEDRIVE $HOMEPATH C: \Users\Bob ``` I am not sure what other environment variables you're interested in. The problem seems to be that bash gets fed the unexpanded cmd-like `%HOMEDRIVE%` and `%HOMEPATH%` paths.
Author
Owner

@zadjii-msft commented on GitHub (Aug 24, 2022):

Alright shoot. I can't repro this on

GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)

git version 2.33.0.vfs.0.0

I wonder if this is a recent regression in git bash. I honestly don't even know the right place to look there.

Like, why is ~ evaluating without expanding %HOMEDRIVE%%HOMEPATH%. That's weird, and that doesn't seem like something that the Terminal would affect.

Does wt -d c:\windows from the Run dialog (win+r) work as expected? I'm totally at a loss here, sorry 😕

@zadjii-msft commented on GitHub (Aug 24, 2022): Alright shoot. I can't repro this on ``` GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu) git version 2.33.0.vfs.0.0 ``` I wonder if this is a recent regression in git bash. I honestly don't even know the right place to look there. Like, why is `~` evaluating without expanding `%HOMEDRIVE%%HOMEPATH%`. That's weird, and that doesn't seem like something that the Terminal would affect. Does `wt -d c:\windows` from the Run dialog (win+r) work as expected? I'm totally at a loss here, sorry 😕
Author
Owner

@MGraefe commented on GitHub (Aug 25, 2022):

Hi, thanks for caring.

I did printenv in both scenarios (broken and working tilde expansion) and diff'ed the result. Seems like a couple of environment variables are screwed up, e.g:

-ORIGINAL_PATH=/mingw64/bin:/usr/bin:%HOMEDRIVE%%HOMEPATH%/bin:(other entries)
+ORIGINAL_PATH=/mingw64/bin:/usr/bin:/c/Users/Bob/bin:/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.14.2281.0_x64__8wekyb3d8bbwe:(other entries)

and probably most important

-HOME=/c/%HOMEDRIVE%%HOMEPATH%
+HOME=/c/Users/Bob

also the PATH contains a couple of %HOMEDRIVE%%HOMEPATH% entries in places where HOME probably gets inserted.

I am not sure what's going on with the env vars when starting from the explorer right-click menu, but something is fairly broken.

@MGraefe commented on GitHub (Aug 25, 2022): Hi, thanks for caring. I did `printenv` in both scenarios (broken and working tilde expansion) and diff'ed the result. Seems like a couple of environment variables are screwed up, e.g: ```diff -ORIGINAL_PATH=/mingw64/bin:/usr/bin:%HOMEDRIVE%%HOMEPATH%/bin:(other entries) +ORIGINAL_PATH=/mingw64/bin:/usr/bin:/c/Users/Bob/bin:/c/Program Files/WindowsApps/Microsoft.WindowsTerminal_1.14.2281.0_x64__8wekyb3d8bbwe:(other entries) ``` and probably most important ```diff -HOME=/c/%HOMEDRIVE%%HOMEPATH% +HOME=/c/Users/Bob ``` also the PATH contains a couple of `%HOMEDRIVE%%HOMEPATH%` entries in places where HOME probably gets inserted. I am not sure what's going on with the env vars when starting from the explorer right-click menu, but something is fairly broken.
Author
Owner

@zadjii-msft commented on GitHub (Aug 25, 2022):

Weird. That's a bit like #7204, but it's almost like HOMEDRIVE and HOMEPATH aren't getting passed s.t. mingw can evaluate them. I wonder if it is because the package dir is getting prepended to the path. I'll leave this open as something in the related web of env var issues. Thanks!

@zadjii-msft commented on GitHub (Aug 25, 2022): Weird. That's a bit like #7204, but it's almost like `HOMEDRIVE` and `HOMEPATH` aren't getting passed s.t. mingw can evaluate them. I wonder if it is because the package dir is getting prepended to the path. I'll leave this open as something in the related web of env var issues. Thanks!
Author
Owner

@MGraefe commented on GitHub (Aug 26, 2022):

Ok, some new findings: I had the environment variable HOME defined as C:\Users\Bob in my normal Windows environment variables user settings. Simply removing that variable makes the tilde expansion for "Open in Terminal" work. I am not sure why I set this environment variable (or which program set it), it's not standard on Windows. Hard to tell when your full-time development machine is getting a bit older...

So most likely Git Bash (or its environment wrapper) has some problems assembling a unix-style HOME path if there's already a HOME environment variable.

However, I am still not sure who is at fault here since everything works fine when I start Windows Terminal regulary. What would be the differences between doing wt -d . in the explorer address bar and doing the right click thingy anyway?!

@MGraefe commented on GitHub (Aug 26, 2022): Ok, some new findings: I had the environment variable `HOME` defined as `C:\Users\Bob` in my normal Windows environment variables user settings. Simply removing that variable makes the tilde expansion for "Open in Terminal" work. I am not sure why I set this environment variable (or which program set it), it's not standard on Windows. Hard to tell when your full-time development machine is getting a bit older... So most likely Git Bash (or its environment wrapper) has some problems assembling a unix-style `HOME` path if there's already a `HOME` environment variable. However, I am still not sure who is at fault here since everything works fine when I start Windows Terminal regulary. What would be the differences between doing `wt -d .` in the explorer address bar and doing the right click thingy anyway?!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18210