use old Arguments instead of ArgumentList to prevent auto escape quote in commands

This commit is contained in:
Hongtao Zhang 2022-05-14 21:25:36 -05:00
parent 15fd62a8b0
commit b7bebc8a32

View file

@ -61,11 +61,9 @@ namespace Flow.Launcher.Plugin.Shell
if (basedir != null) if (basedir != null)
{ {
var autocomplete = Directory.GetFileSystemEntries(basedir). var autocomplete = Directory.GetFileSystemEntries(basedir).Select(o => dir + Path.GetFileName(o)).Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) &&
Select(o => dir + Path.GetFileName(o)). !results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) &&
Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) && !results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) &&
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
autocomplete.Sort(); autocomplete.Sort();
results.AddRange(autocomplete.ConvertAll(m => new Result results.AddRange(autocomplete.ConvertAll(m => new Result
{ {
@ -78,7 +76,7 @@ namespace Flow.Launcher.Plugin.Shell
c.SpecialKeyState.ShiftPressed && c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed && !c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed !c.SpecialKeyState.WinPressed
); );
Execute(Process.Start, PrepareProcessStartInfo(m, runAsAdministrator)); Execute(Process.Start, PrepareProcessStartInfo(m, runAsAdministrator));
return true; return true;
@ -118,7 +116,7 @@ namespace Flow.Launcher.Plugin.Shell
c.SpecialKeyState.ShiftPressed && c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed && !c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed !c.SpecialKeyState.WinPressed
); );
Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator)); Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator));
return true; return true;
@ -148,7 +146,7 @@ namespace Flow.Launcher.Plugin.Shell
c.SpecialKeyState.ShiftPressed && c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed && !c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed !c.SpecialKeyState.WinPressed
); );
Execute(Process.Start, PrepareProcessStartInfo(cmd, runAsAdministrator)); Execute(Process.Start, PrepareProcessStartInfo(cmd, runAsAdministrator));
return true; return true;
@ -173,7 +171,7 @@ namespace Flow.Launcher.Plugin.Shell
c.SpecialKeyState.ShiftPressed && c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed && !c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed !c.SpecialKeyState.WinPressed
); );
Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator)); Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator));
return true; return true;
@ -195,16 +193,18 @@ namespace Flow.Launcher.Plugin.Shell
ProcessStartInfo info = new() ProcessStartInfo info = new()
{ {
Verb = runAsAdministratorArg, Verb = runAsAdministratorArg, WorkingDirectory = workingDirectory,
WorkingDirectory = workingDirectory,
}; };
switch (_settings.Shell) switch (_settings.Shell)
{ {
case Shell.Cmd: case Shell.Cmd:
{ {
info.FileName = "cmd.exe"; info.FileName = "cmd.exe";
info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c"); info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command}";
info.ArgumentList.Add(command);
// ArgumentList may break original shell command separation with quote.
// info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c");
// info.ArgumentList.Add(command);
break; break;
} }
@ -226,7 +226,10 @@ namespace Flow.Launcher.Plugin.Shell
case Shell.RunCommand: case Shell.RunCommand:
{ {
var parts = command.Split(new[] { ' ' }, 2); var parts = command.Split(new[]
{
' '
}, 2);
if (parts.Length == 2) if (parts.Length == 2)
{ {
var filename = parts[0]; var filename = parts[0];
@ -366,7 +369,7 @@ namespace Flow.Launcher.Plugin.Shell
Title = context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_different_user"), Title = context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_different_user"),
Action = c => Action = c =>
{ {
Task.Run(() =>Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title))); Task.Run(() => Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title)));
return true; return true;
}, },
IcoPath = "Images/user.png" IcoPath = "Images/user.png"
@ -396,4 +399,4 @@ namespace Flow.Launcher.Plugin.Shell
return resultlist; return resultlist;
} }
} }
} }