Skip to content

Commit 6c4e948

Browse files
authored
Merge pull request #3657 from Flow-Launcher/shell_problem
Fix command issue for pswh.exe
2 parents 9093e4f + d7c7ec8 commit 6c4e948

File tree

1 file changed

+74
-67
lines changed
  • Plugins/Flow.Launcher.Plugin.Shell

1 file changed

+74
-67
lines changed

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

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -201,94 +201,101 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
201201
switch (_settings.Shell)
202202
{
203203
case Shell.Cmd:
204-
{
205-
if (_settings.UseWindowsTerminal)
206-
{
207-
info.FileName = "wt.exe";
208-
info.ArgumentList.Add("cmd");
209-
}
210-
else
211204
{
212-
info.FileName = "cmd.exe";
213-
}
205+
if (_settings.UseWindowsTerminal)
206+
{
207+
info.FileName = "wt.exe";
208+
info.ArgumentList.Add("cmd");
209+
}
210+
else
211+
{
212+
info.FileName = "cmd.exe";
213+
}
214214

215-
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" : "")}");
216-
break;
217-
}
215+
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" : "")}");
216+
break;
217+
}
218218

219219
case Shell.Powershell:
220-
{
221-
if (_settings.UseWindowsTerminal)
222-
{
223-
info.FileName = "wt.exe";
224-
info.ArgumentList.Add("powershell");
225-
}
226-
else
227220
{
228-
info.FileName = "powershell.exe";
229-
}
230-
if (_settings.LeaveShellOpen)
231-
{
232-
info.ArgumentList.Add("-NoExit");
233-
info.ArgumentList.Add(command);
234-
}
235-
else
236-
{
237-
info.ArgumentList.Add("-Command");
238-
info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}");
221+
// Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window
222+
// \\ must be escaped for it to work properly, or breaking it into multiple arguments
223+
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
224+
if (_settings.UseWindowsTerminal)
225+
{
226+
info.FileName = "wt.exe";
227+
info.ArgumentList.Add("powershell");
228+
}
229+
else
230+
{
231+
info.FileName = "powershell.exe";
232+
}
233+
if (_settings.LeaveShellOpen)
234+
{
235+
info.ArgumentList.Add("-NoExit");
236+
info.ArgumentList.Add(command);
237+
}
238+
else
239+
{
240+
info.ArgumentList.Add("-Command");
241+
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" : "")}");
242+
}
243+
break;
239244
}
240-
break;
241-
}
242245

243246
case Shell.Pwsh:
244-
{
245-
if (_settings.UseWindowsTerminal)
246-
{
247-
info.FileName = "wt.exe";
248-
info.ArgumentList.Add("pwsh");
249-
}
250-
else
251-
{
252-
info.FileName = "pwsh.exe";
253-
}
254-
if (_settings.LeaveShellOpen)
255247
{
256-
info.ArgumentList.Add("-NoExit");
248+
// Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window
249+
// \\ must be escaped for it to work properly, or breaking it into multiple arguments
250+
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
251+
if (_settings.UseWindowsTerminal)
252+
{
253+
info.FileName = "wt.exe";
254+
info.ArgumentList.Add("pwsh");
255+
}
256+
else
257+
{
258+
info.FileName = "pwsh.exe";
259+
}
260+
if (_settings.LeaveShellOpen)
261+
{
262+
info.ArgumentList.Add("-NoExit");
263+
}
264+
info.ArgumentList.Add("-Command");
265+
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" : "")}");
266+
break;
257267
}
258-
info.ArgumentList.Add("-Command");
259-
info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}");
260-
break;
261-
}
262268

263269
case Shell.RunCommand:
264-
{
265-
var parts = command.Split(new[]
266-
{
267-
' '
268-
}, 2);
269-
if (parts.Length == 2)
270270
{
271-
var filename = parts[0];
272-
if (ExistInPath(filename))
271+
var parts = command.Split(new[]
273272
{
274-
var arguments = parts[1];
275-
info.FileName = filename;
276-
info.ArgumentList.Add(arguments);
273+
' '
274+
}, 2);
275+
if (parts.Length == 2)
276+
{
277+
var filename = parts[0];
278+
if (ExistInPath(filename))
279+
{
280+
var arguments = parts[1];
281+
info.FileName = filename;
282+
info.ArgumentList.Add(arguments);
283+
}
284+
else
285+
{
286+
info.FileName = command;
287+
}
277288
}
278289
else
279290
{
280291
info.FileName = command;
281292
}
282-
}
283-
else
284-
{
285-
info.FileName = command;
286-
}
287293

288-
info.UseShellExecute = true;
294+
info.UseShellExecute = true;
295+
296+
break;
297+
}
289298

290-
break;
291-
}
292299
default:
293300
throw new NotImplementedException();
294301
}

0 commit comments

Comments
 (0)