Skip to content

Commit 835cd75

Browse files
committed
Fix buttons for wsl
1 parent 7d5e092 commit 835cd75

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Files.App/UserControls/TerminalView.xaml.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,25 @@ private void StartShellProcess(TerminalSize size, ShellProfile profile)
360360
EventHandler<object> getResponse = (s, e) =>
361361
{
362362
var pwd = Encoding.UTF8.GetString((byte[])e);
363-
var match = Regex.Match(pwd, @"[a-zA-Z]:\\(((?![<>:""/\\|?*]).)+((?<![ .])\\)?)*");
363+
var match = Regex.Match(pwd, @"[a-zA-Z]:\\(((?![<>:""\r/\\|?*]).)+((?<![ .])\\)?)*");
364364
if (match.Success)
365365
tcs.TrySetResult(match.Value);
366366
};
367367
OnOutput += getResponse;
368-
_terminal.WriteToPseudoConsole(Encoding.UTF8.GetBytes($"cd .\r"));
368+
if (profile.Location.Contains("wsl.exe"))
369+
_terminal.WriteToPseudoConsole(Encoding.UTF8.GetBytes($"wslpath -w \"$(pwd)\"\r"));
370+
else
371+
_terminal.WriteToPseudoConsole(Encoding.UTF8.GetBytes($"cd .\r"));
369372
var pwd = await tcs.Task.WithTimeoutAsync(TimeSpan.FromSeconds(1));
370373
OnOutput -= getResponse;
371374
return pwd;
372375
};
373376
_mainPageModel.SetTerminalFolder = (folder) =>
374377
{
375-
_terminal.WriteToPseudoConsole(Encoding.UTF8.GetBytes($"cd \"{folder}\"\r"));
378+
if (profile.Location.Contains("wsl.exe"))
379+
_terminal.WriteToPseudoConsole(Encoding.UTF8.GetBytes($"cd \"$(wslpath \"{folder}\")\"\r"));
380+
else
381+
_terminal.WriteToPseudoConsole(Encoding.UTF8.GetBytes($"cd \"{folder}\"\r"));
376382
};
377383
};
378384
_terminal.Exited += (s, e) =>
@@ -468,8 +474,8 @@ private async void TerminalView_ActualThemeChanged(Microsoft.UI.Xaml.FrameworkEl
468474
var theme = new DefaultValueProvider().GetPreInstalledThemes().First(x => x.Id == profile.TerminalThemeId);
469475
var backgroundColor = ActualTheme switch
470476
{
471-
Microsoft.UI.Xaml.ElementTheme.Dark => "#000000",
472-
_ => "#FFFFFF"
477+
Microsoft.UI.Xaml.ElementTheme.Dark => "#000000",
478+
_ => "#FFFFFF"
473479
};
474480
var foregroundColor = ActualTheme switch
475481
{

0 commit comments

Comments
 (0)