Skip to content

Commit 6517117

Browse files
committed
Implement pause/exit logic
Signed-off-by: Florian Grabmeier <[email protected]>
1 parent fea6589 commit 6517117

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<system:String x:Key="flowlauncher_plugin_cmd_relace_winr">Replace Win+R</system:String>
66
<system:String x:Key="flowlauncher_plugin_cmd_close_cmd_after_press">Close Command Prompt after pressing any key</system:String>
7+
<system:String x:Key="flowlauncher_plugin_cmd_press_any_key_to_close">Press any key to close this window...</system:String>
78
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">Do not close Command Prompt after command execution</system:String>
89
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Always run as administrator</system:String>
910
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Run as different user</system:String>

Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private List<Result> ResultsFromHistory()
187187
return history.ToList();
188188
}
189189

190-
private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdministrator = false) //TODO: implement logic for CloseCMDAfterPress
190+
private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdministrator = false)
191191
{
192192
command = command.Trim();
193193
command = Environment.ExpandEnvironmentVariables(command);
@@ -203,7 +203,7 @@ private List<Result> ResultsFromHistory()
203203
case Shell.Cmd:
204204
{
205205
info.FileName = "cmd.exe";
206-
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command} {(_settings.CloseShellAfterPress ? "& pause" : "")}";
206+
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command} {(_settings.CloseShellAfterPress ? $"&& echo {context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")} && pause > nul /c" : "")}";
207207

208208
//// Use info.Arguments instead of info.ArgumentList to enable users better control over the arguments they are writing.
209209
//// Previous code using ArgumentList, commands needed to be separated correctly:
@@ -232,11 +232,7 @@ private List<Result> ResultsFromHistory()
232232
else
233233
{
234234
info.ArgumentList.Add("-Command");
235-
info.ArgumentList.Add(command);
236-
if (_settings.CloseShellAfterPress)
237-
{
238-
info.ArgumentList.Add("; pause");
239-
}
235+
info.ArgumentList.Add($"{command}; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'; [System.Console]::ReadKey(); exit" : "")}");
240236
}
241237
break;
242238
}
@@ -249,11 +245,7 @@ private List<Result> ResultsFromHistory()
249245
info.ArgumentList.Add("-NoExit");
250246
}
251247
info.ArgumentList.Add("-Command");
252-
info.ArgumentList.Add(command);
253-
if (_settings.CloseShellAfterPress)
254-
{
255-
info.ArgumentList.Add("; pause");
256-
}
248+
info.ArgumentList.Add($"{command}; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'; [System.Console]::ReadKey(); exit" : "")}");
257249

258250
break;
259251
}

0 commit comments

Comments
 (0)