From b2e754dfd56c9dc40765e54c075b132f3ea930e9 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 5 Jun 2025 18:48:26 +0800 Subject: [PATCH 1/2] Fix command issue for pswh.exe --- Plugins/Flow.Launcher.Plugin.Shell/Main.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index 2613c770b35..2771a9118bd 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -242,6 +242,9 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin case Shell.Pwsh: { + // Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window + // \\ must be escaped for it to work properly, or breaking it into multiple arguments + var addedCharacter = _settings.UseWindowsTerminal ? "\\" : ""; if (_settings.UseWindowsTerminal) { info.FileName = "wt.exe"; @@ -256,7 +259,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin info.ArgumentList.Add("-NoExit"); } info.ArgumentList.Add("-Command"); - info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}"); + info.ArgumentList.Add($"{command}{addedCharacter}; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}"); break; } From d7c7ec8f5ef0fd0ad7472b7df9d204da6784895f Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 5 Jun 2025 18:55:58 +0800 Subject: [PATCH 2/2] Apply for all wt.exe --- Plugins/Flow.Launcher.Plugin.Shell/Main.cs | 144 +++++++++++---------- 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index 2771a9118bd..d0add9f3155 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -201,97 +201,101 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin switch (_settings.Shell) { case Shell.Cmd: - { - if (_settings.UseWindowsTerminal) - { - info.FileName = "wt.exe"; - info.ArgumentList.Add("cmd"); - } - else { - info.FileName = "cmd.exe"; - } + if (_settings.UseWindowsTerminal) + { + info.FileName = "wt.exe"; + info.ArgumentList.Add("cmd"); + } + else + { + info.FileName = "cmd.exe"; + } - info.ArgumentList.Add($"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command} {(_settings.CloseShellAfterPress ? $"&& echo {Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")} && pause > nul /c" : "")}"); - break; - } + info.ArgumentList.Add($"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command} {(_settings.CloseShellAfterPress ? $"&& echo {Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")} && pause > nul /c" : "")}"); + break; + } case Shell.Powershell: - { - if (_settings.UseWindowsTerminal) - { - info.FileName = "wt.exe"; - info.ArgumentList.Add("powershell"); - } - else { - info.FileName = "powershell.exe"; - } - if (_settings.LeaveShellOpen) - { - info.ArgumentList.Add("-NoExit"); - info.ArgumentList.Add(command); - } - else - { - info.ArgumentList.Add("-Command"); - info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}"); + // Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window + // \\ must be escaped for it to work properly, or breaking it into multiple arguments + var addedCharacter = _settings.UseWindowsTerminal ? "\\" : ""; + if (_settings.UseWindowsTerminal) + { + info.FileName = "wt.exe"; + info.ArgumentList.Add("powershell"); + } + else + { + info.FileName = "powershell.exe"; + } + if (_settings.LeaveShellOpen) + { + info.ArgumentList.Add("-NoExit"); + info.ArgumentList.Add(command); + } + else + { + info.ArgumentList.Add("-Command"); + info.ArgumentList.Add($"{command}{addedCharacter}; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'{addedCharacter}; [System.Console]::ReadKey(){addedCharacter}; exit" : "")}"); + } + break; } - break; - } case Shell.Pwsh: - { - // Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window - // \\ must be escaped for it to work properly, or breaking it into multiple arguments - var addedCharacter = _settings.UseWindowsTerminal ? "\\" : ""; - if (_settings.UseWindowsTerminal) - { - info.FileName = "wt.exe"; - info.ArgumentList.Add("pwsh"); - } - else - { - info.FileName = "pwsh.exe"; - } - if (_settings.LeaveShellOpen) { - info.ArgumentList.Add("-NoExit"); + // Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window + // \\ must be escaped for it to work properly, or breaking it into multiple arguments + var addedCharacter = _settings.UseWindowsTerminal ? "\\" : ""; + if (_settings.UseWindowsTerminal) + { + info.FileName = "wt.exe"; + info.ArgumentList.Add("pwsh"); + } + else + { + info.FileName = "pwsh.exe"; + } + if (_settings.LeaveShellOpen) + { + info.ArgumentList.Add("-NoExit"); + } + info.ArgumentList.Add("-Command"); + info.ArgumentList.Add($"{command}{addedCharacter}; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'{addedCharacter}; [System.Console]::ReadKey(){addedCharacter}; exit" : "")}"); + break; } - info.ArgumentList.Add("-Command"); - info.ArgumentList.Add($"{command}{addedCharacter}; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}"); - break; - } case Shell.RunCommand: - { - var parts = command.Split(new[] - { - ' ' - }, 2); - if (parts.Length == 2) { - var filename = parts[0]; - if (ExistInPath(filename)) + var parts = command.Split(new[] { - var arguments = parts[1]; - info.FileName = filename; - info.ArgumentList.Add(arguments); + ' ' + }, 2); + if (parts.Length == 2) + { + var filename = parts[0]; + if (ExistInPath(filename)) + { + var arguments = parts[1]; + info.FileName = filename; + info.ArgumentList.Add(arguments); + } + else + { + info.FileName = command; + } } else { info.FileName = command; } - } - else - { - info.FileName = command; - } - info.UseShellExecute = true; + info.UseShellExecute = true; + + break; + } - break; - } default: throw new NotImplementedException(); }