-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Support linux paths for startingDirectory
of WSL distros
#592
Comments
it looks like it expects Windows paths but passing the WSL fs paths under AppData directly doesn't work. Using the new UNC path works for me: So do regular Windows locations: |
Hmm. We should maybe add a setting to suggest that the startingDirectory is a wsl path. Right now we're just manually setting the working directory of the client app we're starting, so we'd have to specifically know that the profile was trying to be wsl, and adjust our logic for passing in a working directory. |
one easy hack would be inside Problem solved. |
This is also a great way to get weird and unexpected behaviour in everything else that uses bash on your machine. 😄 |
This method is a little bit of work. We could parse out the distribution name from the command in the profile so that Or we could make the method a non-static method and draw the value from EDIT: I realize now that this won't work. The P9 server will likely not have been started, and if it had been, won't have all of the distros loaded as available shares under the UNC path. |
@sandeepkv93 - That hack isn't the best. When working in say VS Code and you want your WSL terminal to open inside your project directory, this will prevent that. Definitely going to cause other problems too |
My workaround
|
I just edited my |
|
What if I want to set the default directory to a directory in C:? |
@leolozes The second post in this thread shows how to do exactly what you want. |
in my case, it works this way |
This comment has been minimized.
This comment has been minimized.
Hi all I know I got a few thumbs down for this suggestion that I posted earlier, but I just installed WSL and Ubuntu-20.04 on a new system and all I did was add the below lines to my settings.json file and it 100% worked for dropping me into my home directory. I am not saying it will work for everyone as I am not sure the thumbs down users actually tested this or not, but it has worked for me on 2 different systems both with Ubuntu-20.04 and 18.04. I think it is the easiest thing to try first and if it does not work for you then try a couple other suggestions on this thread. "startingDirectory": "//wsl$/Ubuntu-20.04/home/troy-mac" or use @antoineco suggestion which may work all the time... |
@troy-mac I'm speaking for myself here, but the thumb down was a way to say "Warning, reader. The solution suggested in this message doesn't work for everyone, please refer to the accepted solution instead". It wasn't an attempt to dismiss you. Like you said, |
When installing Ubuntu, can use
If not certain what [DISTRONAME] is, do:
Now you will get the fileshare in an explorer. Fx Simply follow the path to where you want to start from when opening a new tab in Windows Terminal. Remember:
when construcing the |
@Ratismal "startingDirectory": "//wsl$/Ubuntu/home/cat/proj" I think it's case-sensitive to the distro name. |
@zadjii-msft forward slashes unescaped work for me: |
You were exactly right, thank you! I think there might be a bug somewhere in there, though? Did some experimenting.
I would expect that case sensitivity would cause |
Frankly, I have no idea how the WSL filesystem driver works. The best place to ask would be over at https://github.com/microsoft/WSL |
This seems to be the commonly accepted solution but it has one fatal flaw: if you use I use the Windows Subsystem for Linux for spinning up sand-boxes for developer experiments, using
This works great because I can use commands like Obviously, not appending |
Using the new UNC path as suggested by caksoylar worked great for me, but just a note to others that, for example, if you have "Ubuntu", it may not just be "Ubuntu". Mine was actually I was able to confirm this by opening up VSCode and using "reveal in explorer" on a file, to which it then opened You can also just do |
for me since version 1.9.1445.0 (preview) this no longer worked { however this works |
This works for me: cd into the directory where I want to start and type |
Is this still true?? I seems to be, it is for me. So is there no way to always (even the first time) start up a WSL instance in the Linux home directory? That seems really strange, especially in WSL2 where the division between file systems is greater because of performance differences. |
This commit introduces a hack to ConptyConnection for launching WSL. When we detect that WSL is being launched (either "wsl" or "wsl.exe", unqialified or _specifically_ from the current OS's System32 directory), we will promote the startingDirectory specified at launch time into a commandline argument. Why do we want to switch to `--cd`? With the current design of ConptyConnection and WSL, there are some significant limitations: * `startingDirectory` cannot be a WSL path, which forces users to use weird tricks such as setting the starting directory to `\\wsl$\Distro\home\user`. * WSL occasionally fails to launch in time to handle a `\\wsl$` path, which makes us spawn in a strange location (or no location at all). (This fix will only address the second one until a WSL update is released that adds support for `--cd $LINUX_PATH`.) We will not do the promotion if any of the following are true: * the commandline contains `--cd` already * the commandline contains a bare `~` * This was a commonly-used workaround that forced wsl to start in the user's home directory. It conflicts with --cd. * wsl is not spelled properly (`WSL` and `WSL.EXE` are unacceptable) * an absolute path to wsl outside the system32 directory is provided We chose the do this trick in the connection layer, the latest possible point, because it captures the most use cases. We could have done it earlier, but the options were quite limiting. They are: * Generate WSL profiles with startingDirectory set to the home folder * We can't do this because we do not know the user's home folder path. * Generate WSL profiles with `--cd` in them. * This only works for unmodified profiles. * This only works for generated profiles. * Users cannot override the commandline without breaking it. * Users cannot specify a startingDirectory (!) since the one on the commandline wins. * Set a flag on generated WSL profiles to request this trick * This only works for generated profiles. Users who create their own WSL profiles couldn't set startingDirectory and have it work the same. Patching the commandline, hacky though it may be, seemed to be the most compatible option. Eventually, we can even support `wt -d ~ wsl`! ## Validation Steps Performed Manual validation for the following cases: ```c++ // MUST MANGLE auto a01 = _tryMangleStartingDirectoryForWSL(LR"(wsl)", L"SENTINEL"); auto a02 = _tryMangleStartingDirectoryForWSL(LR"(wsl -d X)", L"SENTINEL"); auto a03 = _tryMangleStartingDirectoryForWSL(LR"(wsl -d X ~/bin/sh)", L"SENTINEL"); auto a04 = _tryMangleStartingDirectoryForWSL(LR"(wsl.exe)", L"SENTINEL"); auto a05 = _tryMangleStartingDirectoryForWSL(LR"(wsl.exe -d X)", L"SENTINEL"); auto a06 = _tryMangleStartingDirectoryForWSL(LR"(wsl.exe -d X ~/bin/sh)", L"SENTINEL"); auto a07 = _tryMangleStartingDirectoryForWSL(LR"("wsl")", L"SENTINEL"); auto a08 = _tryMangleStartingDirectoryForWSL(LR"("wsl.exe")", L"SENTINEL"); auto a09 = _tryMangleStartingDirectoryForWSL(LR"("wsl" -d X)", L"SENTINEL"); auto a10 = _tryMangleStartingDirectoryForWSL(LR"("wsl.exe" -d X)", L"SENTINEL"); auto a11 = _tryMangleStartingDirectoryForWSL(LR"("C:\Windows\system32\wsl.exe" -d X)", L"SENTINEL"); auto a12 = _tryMangleStartingDirectoryForWSL(LR"("C:\windows\system32\wsl" -d X)", L"SENTINEL"); auto a13 = _tryMangleStartingDirectoryForWSL(LR"(wsl ~/bin)", L"SENTINEL"); // MUST NOT MANGLE auto a14 = _tryMangleStartingDirectoryForWSL(LR"("C:\wsl.exe" -d X)", L"SENTINEL"); auto a15 = _tryMangleStartingDirectoryForWSL(LR"(C:\wsl.exe)", L"SENTINEL"); auto a16 = _tryMangleStartingDirectoryForWSL(LR"(wsl --cd C:\)", L"SENTINEL"); auto a17 = _tryMangleStartingDirectoryForWSL(LR"(wsl ~)", L"SENTINEL"); auto a18 = _tryMangleStartingDirectoryForWSL(LR"(wsl ~ -d Ubuntu)", L"SENTINEL"); ``` We don't have anywhere to put TerminalConnection unit tests :| Closes #592.
🎉This issue was addressed in #9223, which has now been successfully released as Handy links: |
I've recently discovered that having Is there some other way via WSL to specify the working directory for the distro instead of it always pointing at |
Your Windows build number:
Microsoft Windows [Version 10.0.18362.86]
What you're doing and what's happening:
Setting the starting directory for wsl in
profiles.json
doesn't make it point to the right directory.This results in wsl starting up in the root folder
This results in wsl starting up in the Windows user folder
The
startingDirectory
profile setting is not being applied correctly on a wsl profileThe text was updated successfully, but these errors were encountered: