From 07f440768e9e499e55d7b901a91fb2c73e4e5be1 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 15 Jun 2025 21:21:46 +0800 Subject: [PATCH 1/2] Fix one more whitespace after commands --- Plugins/Flow.Launcher.Plugin.Shell/Main.cs | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index d0add9f3155..37f382ad14c 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -194,10 +194,12 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? "" : "runas"; - ProcessStartInfo info = new() + var info = new ProcessStartInfo() { - Verb = runAsAdministratorArg, WorkingDirectory = workingDirectory, + Verb = runAsAdministratorArg, + WorkingDirectory = workingDirectory, }; + var notifyStr = Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close"); switch (_settings.Shell) { case Shell.Cmd: @@ -212,7 +214,11 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin 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" : "")}"); + info.ArgumentList.Add( + $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command}" + + $"{(_settings.CloseShellAfterPress ? + $" && echo {notifyStr} && pause > nul /c" : + "")}"); break; } @@ -238,7 +244,11 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin 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" : "")}"); + info.ArgumentList.Add( + $"{command}{addedCharacter};" + + $"{(_settings.CloseShellAfterPress ? + $" Write-Host '{notifyStr}'{addedCharacter}; [System.Console]::ReadKey(){addedCharacter}; exit" : + "")}"); } break; } @@ -262,7 +272,11 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin 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" : "")}"); + info.ArgumentList.Add( + $"{command}{addedCharacter};" + + $"{(_settings.CloseShellAfterPress ? + $" Write-Host '{notifyStr}'{addedCharacter}; [System.Console]::ReadKey(){addedCharacter}; exit" : + "")}"); break; } From 89214fb58a0844854a99fcd8ac35a185436caa6d Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Mon, 16 Jun 2025 12:38:31 +0800 Subject: [PATCH 2/2] Improve code quality --- Plugins/Flow.Launcher.Plugin.Shell/Main.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index 37f382ad14c..a51aadec7df 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -200,6 +200,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin WorkingDirectory = workingDirectory, }; var notifyStr = Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close"); + var addedCharacter = _settings.UseWindowsTerminal ? "\\" : ""; switch (_settings.Shell) { case Shell.Cmd: @@ -213,9 +214,16 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin { info.FileName = "cmd.exe"; } - + if (_settings.LeaveShellOpen) + { + info.ArgumentList.Add("/k"); + } + else + { + info.ArgumentList.Add("/c"); + } info.ArgumentList.Add( - $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command}" + + $"{command}" + $"{(_settings.CloseShellAfterPress ? $" && echo {notifyStr} && pause > nul /c" : "")}"); @@ -226,7 +234,6 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin { // 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"; @@ -257,7 +264,6 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin { // 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";