-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Opening Windows Terminal in current directory from right-click folder context menu (the ubuntu.exe
bug)
#12961
Comments
What version are you on? Could you share your settings.json file? I'm mildly worried that our aside: Is there a reason you're not just using the explorer context menu entry that the Terminal creates itself when you install it/? |
Sure, here's my settings.json: {
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions":
[
{
"command":
{
"action": "copy",
"singleLine": false
},
"keys": "ctrl+c"
},
{
"command": "paste",
"keys": "ctrl+v"
},
{
"command": "find",
"keys": "ctrl+shift+f"
},
{
"command":
{
"action": "splitPane",
"split": "auto",
"splitMode": "duplicate"
},
"keys": "alt+shift+d"
}
],
"copyFormatting": "none",
"copyOnSelect": false,
"defaultProfile": "{51855cb2-8cce-5362-8f54-464b92b32386}",
"language": "en-US",
"profiles":
{
"defaults": {},
"list":
[
{
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"hidden": false,
"name": "Windows PowerShell"
},
{
"commandline": "%SystemRoot%\\System32\\cmd.exe",
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "Prompt dei comandi"
},
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": true,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "%USERPROFILE%"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{5b849eef-e172-55b9-8019-ef031bec368c}",
"hidden": false,
"name": "Developer Command Prompt for VS 2022",
"source": "Windows.Terminal.VisualStudio"
},
{
"guid": "{8c6e956b-317a-5194-b80e-c5281032870f}",
"hidden": false,
"name": "Developer PowerShell for VS 2022",
"source": "Windows.Terminal.VisualStudio"
},
{
"guid": "{51855cb2-8cce-5362-8f54-464b92b32386}",
"hidden": false,
"name": "Ubuntu",
"source": "CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc",
"startingDirectory": "%USERPROFILE%"
}
]
},
"schemes":
[
... unimportant I guess...
]
} For the second question: the context menu entry created at install time doesn't set the starting directory to the current one I was browsing while I clicked with Shift+RightClick either, seems to work with the WSL profile, not with the other Ubuntu profile. |
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": true,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "%USERPROFILE%"
},
// ...
{
"guid": "{51855cb2-8cce-5362-8f54-464b92b32386}",
"hidden": false,
"name": "Ubuntu",
"source": "CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc",
"startingDirectory": "%USERPROFILE%"
} Interesting - canonical is shipping their own profile, but not one layered with the existing profile. Curious.... |
Interesting. I really can't get this to repro... Is this always affecting a specific path? I know there have been troubles with doing this in the root of a drive before (e.g. Which OS version and Terminal version are you on/? IIRC there were some os-side issues with Directory/Background entries in the past |
Windows 10 (10.0.19044 Build 19044), wt 1.12.10982.0. It is affecting any path that I could try, not only root drives but also child dirs. |
Oh heck that's probably it! I bet they've got the |
Is your profile using The latter will not respect the starting directory, and always opens in $HOME |
That's exactly it. There's definitely and issue with the Ubuntu profiles that Canonical is shipping. Sorry about that! I'm reaching out to them to see what we can do here. |
Same problem here after removing one of the distros I had installed; Windows Terminal settings also still recognizing two distros at the selection for the default one. |
Workaround - add the following in
|
Did you ever figure out why we have two? Which one should we use? |
Thank you! Why didn't I think of this? |
Can't really think of a downside, unless you explicitly want to open terminal in the system directory. The only thing that still doesn't work with this setup is opening terminal within a network share. It ends up landing in |
WSL does not automatically map network shares. It cannot be launched in any directory that is not represented or representable in the Linux filesystem. You would need to mount them explicitly in This would make an excellent feature request for the WSL repo 😄 |
I could have sworn I had this working in WSL2. But I could be getting confused with my previous cygwin setup. |
Ah, even WSL 1 doesn't automatically map network shares. |
Exactly my question. Why are 2 profiles generated and the bad one is enabled and not vice versa? From all the related bugs, the profile generated by ? (with the Tux icon) is the correct one and the one generated by Canonical (with the Ubuntu icon, IMO, from user's perspective, this seems absurd, so it would deserve at least a short explanation. And also a dedicated issue like #15560 - @zadjii-msft, are you really sure you want to continue the discussion here, where logically stuff quite unrelated to this profiles bug (like "mapping network shares" just above) were and will be discussed? Anyway, thank you guys for pushing this further, I believe this confuses tons of people and is a huge waste of time in the sum. |
This is a choice in the Canonical code snippet, it creates a new profile and (attempts to) disable the built-in generator's profile. Nothing we can do about it in the WT code except break that feature, which seems unlikely to be an acceptable choice. Having just help a user hitting this issue starting from #3158 (comment), here's what appears to be the current state of making the Ubuntu-provided profile (or any other WSL distribution's custom profile) work, thanks to comments earlier in this ticket, and some testing by the user having the issue. If you want to use the Ubuntu generated profile, you need to do one of two things:
"commandline": "wsl.exe -d Ubuntu-22.04",
"startingDirectory": "~", Note that this approach loses anything the Ubuntu launcher does before it chains out into wsl.exe. I think that is only first-run stuff, but I expect it does make this approach a non-starter for the Ubuntu-provided snippet.
"commandline": "ubuntu2204.exe run",
"startingDirectory": "\\\\wsl$\\Ubuntu-2404\\home\\<yourWSLAccountName>", You can get the In both cases the Both approaches should make both "open-in-current-directory folder context menu" and "OSC9;9 duplicate current session" work, as AFAIK they rely on being able to override the profile's defined Note that if you're adding There's two current code-paths in WT that are issues for this ticket AFAIK:
So there's probably some low-hanging fruit for someone to unify those two hacks to both work the same way. (Of the two hacks, I think matching wsl.exe is better than checking the And some higher-branch fruit to then expose them as not-hacks by perhaps either detecting WSL or exposing an Other solutions are possible, of course, and I make no suggestion on the acceptability of my suggestions to the WT maintainers. |
Thanks for the investigation! One note about this: we use |
Ah, yes. I misparsed the code: the So it does make sense to use |
Is there any way to extract the value set via OSC9;9 and use within "commandline" ? How do we generalize the dup functionality to work for ssh sessions (and other arbitrary commands)? It seems like it can only be used for WSL/cmd/PS sessions. something like : |
I think that this is the wrong ticket for this question...? But no, I don't think that data is currently exposed in env-vars or otherwise, it's only used to set the starting directory for the new process as far as I can see. (But I only quickly checked the code for launching processes on GitHub, so it's possible it's exposed somehow elsewhere and I overlooked it.) That should already work for arbitrary commands, as long as they also output OSC9;9 escapes to set the value, e.g., So you would need to open a feature request ticket if you want that available. Note that OSC9;9 paths are Windows paths, so unless you're SSHing to a Windows server, it won't be the right value for you anyway. For that, you'll need OSC7 support, and we don't have that in Windows Terminal yet, it's being "tracked" in #3158. But maybe the resolution to the long standing "OSC7 semantics are challenging and ill-defined" issue for us could be as simple as "Capture OSC7, and expose it as an env-var in duplicate tabs so people can use a commandline like Okay maybe it is relevant to this ticket; if But I still think the general idea of "Capture OSC7 and expose it as an env-var for commandlines/processes to use as they see fit" might be worth a feature request. (That would also let us close #3158 as "We're not using OSC7 for automatic CWD setting, we only support OSC9;9 for that"...) |
Hmm, I don't think that's right? For instance, from a WSL session I can emit OSC9;9 with a linux path, using "\w" escape that bash understands with PS1 environment variable. I don't have to "window-ize" the path using wslpath. Focus-panes duplicate properly and inherent the PWD. It's not at all clear in the code that OSC9;9 can only refer to a Windows path? (though I am new to this codebase, I just scanned quickly) |
I'd happy with either OSC7 or OSC9;9 turning into an env var, and dropping WSL-specific hack. I don't totally follow the argument for why OSC9;9 was introduced vs reusing OSC7 but I'll leave that to others who've thought about it longer/harder. EDIT: I just found MangleStartingDirectoryForWSL() ... YUCK! |
The only reason it works with WSL profiles without wslpath is because WT doesn't validate the path at all, and then the existing hack to make in-WSL paths work kicks in. If we ever implement a feature to open other profiles with the current directory then you'll need to be using wslpath if you want to open, e.g., pwsh in the same directory as your current WSL session. Even right now, if you open a pwsh session, and run WSL inside it, without wslpath'ing your OSC9;9 path, duplicating the tab will So I'd strongly suggest using wslpath now to avoid future "Why doesn't it work now?" surprises. |
Basically, everytime someone from the Windows world tried to implement OSC7, a bunch of corner cases showed up for POSIX paths, and we also re-learned that Windows defines the file: url differently in different places. OSC9;9 is specific to Windows-based terminal emulators so it was easier to implement first. |
I don't follow. This is exactly what breaks in the 'ssh' scenario, where wslpath is not available. In any case, should I attempt to file a a feature request (to make either OSC9;9 or OSC7 info available via env var) or presume that it will implicitly follow from this discussion? |
I was referring to the comment about WSL sessions apparently not needing Anyway... yes, I'd recommend filing a feature request; that way it'll be more clearly in front of the project developers, and if nothing else, should receive feedback on better ways to achieve what you need, and/or better implementations that "Expose as env-var". |
|
Description of the new feature/enhancement
I couldn't find a way to open up
wt.exe
in a linux profile (e.g.Ubuntu
) via right-click in the context menu that pops up in explorer by setting the current working directory to whatever I was browsing before.To rephrase: I added some
HKCR\Directory\Background\shell\wt\command
key withwt.exe -d "%V"
so that I can Shift+RightClick in a folder in explorer.exe and have aOpen in Windows Terminal with Linux
item in the context menu. Windows Terminal opens but the starting directory, no matter what I set the profilestartingDirectory
field in the JSON to, is always set to my home directory. It would be nice ifwt.exe -d "C:\\"
or whatever actually opened, for the linux profile, in/mnt/c
as starting directory.The text was updated successfully, but these errors were encountered: