Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MGraefe opened this issue Aug 19, 2022 · 7 comments
Open

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

MGraefe opened this issue Aug 19, 2022 · 7 comments
Labels
Culprit-Centennial Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.
Milestone

Comments

@MGraefe
Copy link

MGraefe commented 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)
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Aug 19, 2022
@MGraefe MGraefe changed the title "Open in Windows Terminal" with git bash as default breaks shell login "Open in Windows Terminal" with git bash as default breaks tilde expansion Aug 19, 2022
@MGraefe MGraefe changed the title "Open in Windows Terminal" with git bash as default breaks tilde expansion "Open in Terminal" with git bash as default breaks tilde expansion Aug 19, 2022
@zadjii-msft
Copy link
Member

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 zadjii-msft added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-Terminal The new Windows Terminal. labels Aug 19, 2022
@ghost ghost added the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Aug 23, 2022
@ghost
Copy link

ghost commented 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.

@MGraefe
Copy link
Author

MGraefe commented 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.

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. labels Aug 24, 2022
@zadjii-msft
Copy link
Member

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 😕

@MGraefe
Copy link
Author

MGraefe commented 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.

@zadjii-msft
Copy link
Member

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 zadjii-msft added Issue-Bug It either shouldn't be doing this or needs an investigation. Culprit-Centennial and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Attention The core contributors need to come back around and look at this ASAP. labels Aug 25, 2022
@zadjii-msft zadjii-msft added this to the Backlog milestone Aug 25, 2022
@MGraefe
Copy link
Author

MGraefe commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Culprit-Centennial Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

2 participants