Skip to content

Commit d7c7ec8

Browse files
committed
Apply for all wt.exe
1 parent b2e754d commit d7c7ec8

File tree

1 file changed

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

1 file changed

+74
-70
lines changed

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

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -201,97 +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-
// Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window
246-
// \\ must be escaped for it to work properly, or breaking it into multiple arguments
247-
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
248-
if (_settings.UseWindowsTerminal)
249-
{
250-
info.FileName = "wt.exe";
251-
info.ArgumentList.Add("pwsh");
252-
}
253-
else
254-
{
255-
info.FileName = "pwsh.exe";
256-
}
257-
if (_settings.LeaveShellOpen)
258247
{
259-
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;
260267
}
261-
info.ArgumentList.Add("-Command");
262-
info.ArgumentList.Add($"{command}{addedCharacter}; {(_settings.CloseShellAfterPress ? $"Write-Host '{Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}");
263-
break;
264-
}
265268

266269
case Shell.RunCommand:
267-
{
268-
var parts = command.Split(new[]
269-
{
270-
' '
271-
}, 2);
272-
if (parts.Length == 2)
273270
{
274-
var filename = parts[0];
275-
if (ExistInPath(filename))
271+
var parts = command.Split(new[]
276272
{
277-
var arguments = parts[1];
278-
info.FileName = filename;
279-
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+
}
280288
}
281289
else
282290
{
283291
info.FileName = command;
284292
}
285-
}
286-
else
287-
{
288-
info.FileName = command;
289-
}
290293

291-
info.UseShellExecute = true;
294+
info.UseShellExecute = true;
295+
296+
break;
297+
}
292298

293-
break;
294-
}
295299
default:
296300
throw new NotImplementedException();
297301
}

0 commit comments

Comments
 (0)