WSL Commands work in Windows folders - not WSL folders

Hello!

I've been trying to use the built in WSL support and it works great if I'm in a windows directory, say D:\Work\Docs.
I can open WSL terminal in the folder with CLI DOSPROMPT=noadmin,wsl or type a command in the current folder like |ls and everything works as expected.

This all, oddly enough, stops working if I'm in a WSL managed directory.
If I'm in \\wsl.localhost\Ubuntu\home\furd\code and attempt to launch a new terminal with CLI DOSPROMPT=noadmin,wsl it results in:

<3>WSL (299538) ERROR: CreateProcessParseCommon:789: Failed to translate Z:\home\furd\code

if I try to run |ls it ends up running the ls command in the /mnt/c/WINDOWS/system32 folder.

This is using Windows 11 and WSL version: 1.2.5.0

Just to confirm, this still happens in the 12.31.1 beta.

Thanks for the report. This is a limitation of the current design, which was intended to make "regular" (drive letter) paths usable with WSL. We do intend to improve this in the future.

3 Likes

Understandable, looking forward to when it works in both contexts!

In the meantime, at least for the terminal button portion, I assume a button could be made that looks at the current path and if it's a wsl path it runs the terminal using wsl.exe instead.

You could do that using a small bit of JScript in the button.

Worked well, though I've got a quick question about the "right" way to get the current tabs path.
I'd assume pathpart would be the current directory the tab is in, dropping any selected file from the string but it seems to drop the final path segment from the output.

Is there a better way to get the full path than forcing the path into a string?

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	// What's the best way to get the full directory path as a string?
	// pathpart seems to drop the final directory, I assumed it would just leave off the filename
	var pathstring = clickData.func.sourcetab.path + "";
	cmd.deselect = false;

	if (pathstring.indexOf("\\\\wsl.localhost\\", -1) == 0) {
		cmd.RunCommand("wsl.exe --cd " + pathstring);
	} else {
		cmd.RunCommand("CLI DOSPROMPT=noadmin,wsl");
	}
}

path.pathpart will get you the parent of path. (If you want the whole path, that's what the object itself returns by default.)

You don't have to convert it to a string, since that happens implicitly when you add it to the command string. Doing so doesn't hurt, though. What you have looks fine.

1 Like

Since I was doing .indexOf I had to coerce it into a string, otherwise you end up with Object doesn't support this property or method

Thanks for the check!

1 Like