Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions Plugins/Flow.Launcher.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,26 @@ public List<Result> Query(Query query)

if (basedir != null)
{
var autocomplete = Directory.GetFileSystemEntries(basedir).
Select(o => dir + Path.GetFileName(o)).
Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) &&
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) &&
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();
var autocomplete =
Directory.GetFileSystemEntries(basedir)
.Select(o => dir + Path.GetFileName(o))
.Where(o => o.StartsWith(cmd, StringComparison.OrdinalIgnoreCase) &&
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase)) &&
!results.Any(p => o.Equals(p.Title, StringComparison.OrdinalIgnoreCase))).ToList();

autocomplete.Sort();

results.AddRange(autocomplete.ConvertAll(m => new Result
{
Title = m,
IcoPath = Image,
Action = c =>
{
var runAsAdministrator = (
var runAsAdministrator =
c.SpecialKeyState.CtrlPressed &&
c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed
);
!c.SpecialKeyState.WinPressed;

Execute(Process.Start, PrepareProcessStartInfo(m, runAsAdministrator));
return true;
Expand Down Expand Up @@ -113,12 +115,11 @@ private List<Result> GetHistoryCmds(string cmd, Result result)
IcoPath = Image,
Action = c =>
{
var runAsAdministrator = (
var runAsAdministrator =
c.SpecialKeyState.CtrlPressed &&
c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed
);
!c.SpecialKeyState.WinPressed;

Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator));
return true;
Expand All @@ -143,12 +144,11 @@ private Result GetCurrentCmd(string cmd)
IcoPath = Image,
Action = c =>
{
var runAsAdministrator = (
var runAsAdministrator =
c.SpecialKeyState.CtrlPressed &&
c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed
);
!c.SpecialKeyState.WinPressed;

Execute(Process.Start, PrepareProcessStartInfo(cmd, runAsAdministrator));
return true;
Expand All @@ -168,12 +168,11 @@ private List<Result> ResultsFromlHistory()
IcoPath = Image,
Action = c =>
{
var runAsAdministrator = (
var runAsAdministrator =
c.SpecialKeyState.CtrlPressed &&
c.SpecialKeyState.ShiftPressed &&
!c.SpecialKeyState.AltPressed &&
!c.SpecialKeyState.WinPressed
);
!c.SpecialKeyState.WinPressed;

Execute(Process.Start, PrepareProcessStartInfo(m.Key, runAsAdministrator));
return true;
Expand Down Expand Up @@ -203,8 +202,21 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
case Shell.Cmd:
{
info.FileName = "cmd.exe";
info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c");
info.ArgumentList.Add(command);
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command}";

//// Use info.Arguments instead of info.ArgumentList to enable users better control over the arguments they are writing.
//// Previous code using ArgumentList, commands needed to be seperated correctly:
//// Incorrect:
// info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commented out code is not removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we can remove it. Probably it would be better to change all argumentlist to plain arguments, because we want to allow user to have the most control over the argument they are writing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes agree.

// info.ArgumentList.Add(command); //<== info.ArgumentList.Add("mkdir \"c:\\test new\"");

//// Correct version should be:
//info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c");
//info.ArgumentList.Add("mkdir");
//info.ArgumentList.Add(@"c:\test new");

//https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0#remarks

break;
}

Expand Down Expand Up @@ -366,7 +378,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
Title = context.API.GetTranslation("flowlauncher_plugin_cmd_run_as_different_user"),
Action = c =>
{
Task.Run(() =>Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title)));
Task.Run(() => Execute(ShellCommand.RunAsDifferentUser, PrepareProcessStartInfo(selectedResult.Title)));
return true;
},
IcoPath = "Images/user.png"
Expand Down Expand Up @@ -396,4 +408,4 @@ public List<Result> LoadContextMenus(Result selectedResult)
return resultlist;
}
}
}
}