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
36 changes: 28 additions & 8 deletions Plugins/Flow.Launcher.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
string basedir = null;
string dir = null;
string excmd = Environment.ExpandEnvironmentVariables(cmd);
if (Directory.Exists(excmd) && (cmd.EndsWith("/") || cmd.EndsWith(@"\")))

Check warning on line 48 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
{
basedir = excmd;

Check warning on line 50 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
dir = cmd;
}
else if (Directory.Exists(Path.GetDirectoryName(excmd) ?? string.Empty))

Check warning on line 53 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
{
basedir = Path.GetDirectoryName(excmd);

Check warning on line 55 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`excmd` is not a recognized word. (unrecognized-spelling)
var dirName = Path.GetDirectoryName(cmd);
dir = (dirName.EndsWith("/") || dirName.EndsWith(@"\")) ? dirName : cmd[..(dirName.Length + 1)];
}
Expand Down Expand Up @@ -129,7 +129,7 @@
}).Where(o => o != null);

if (_settings.ShowOnlyMostUsedCMDs)
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();

Check warning on line 132 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`CMDs` is not a recognized word. (unrecognized-spelling)

return history.ToList();
}
Expand Down Expand Up @@ -181,8 +181,8 @@
CopyText = m.Key
});

if (_settings.ShowOnlyMostUsedCMDs)

Check warning on line 184 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`CMDs` is not a recognized word. (unrecognized-spelling)
return history.Take(_settings.ShowOnlyMostUsedCMDsNumber).ToList();

Check warning on line 185 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`CMDs` is not a recognized word. (unrecognized-spelling)

return history.ToList();
}
Expand All @@ -194,10 +194,13 @@
var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? "" : "runas";

ProcessStartInfo info = new()
var info = new ProcessStartInfo()
{
Verb = runAsAdministratorArg, WorkingDirectory = workingDirectory,
Verb = runAsAdministratorArg,
WorkingDirectory = workingDirectory,
};
var notifyStr = Context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close");
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
switch (_settings.Shell)
{
case Shell.Cmd:
Expand All @@ -211,16 +214,26 @@
{
info.FileName = "cmd.exe";
}

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" : "")}");
if (_settings.LeaveShellOpen)
{
info.ArgumentList.Add("/k");
}
else
{
info.ArgumentList.Add("/c");
}
info.ArgumentList.Add(
$"{command}" +
$"{(_settings.CloseShellAfterPress ?
$" && echo {notifyStr} && pause > nul /c" :
"")}");
break;
}

case Shell.Powershell:
{
// Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window
// \\ must be escaped for it to work properly, or breaking it into multiple arguments
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
if (_settings.UseWindowsTerminal)
{
info.FileName = "wt.exe";
Expand All @@ -238,7 +251,11 @@
else
{
info.ArgumentList.Add("-Command");
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" : "")}");
info.ArgumentList.Add(
$"{command}{addedCharacter};" +
$"{(_settings.CloseShellAfterPress ?
$" Write-Host '{notifyStr}'{addedCharacter}; [System.Console]::ReadKey(){addedCharacter}; exit" :
"")}");
}
break;
}
Expand All @@ -247,7 +264,6 @@
{
// Using just a ; doesn't work with wt, as it's used to create a new tab for the terminal window
// \\ must be escaped for it to work properly, or breaking it into multiple arguments
var addedCharacter = _settings.UseWindowsTerminal ? "\\" : "";
if (_settings.UseWindowsTerminal)
{
info.FileName = "wt.exe";
Expand All @@ -255,14 +271,18 @@
}
else
{
info.FileName = "pwsh.exe";

Check warning on line 274 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`pwsh` is not a recognized word. (unrecognized-spelling)
}
if (_settings.LeaveShellOpen)
{
info.ArgumentList.Add("-NoExit");
}
info.ArgumentList.Add("-Command");
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" : "")}");
info.ArgumentList.Add(
$"{command}{addedCharacter};" +
$"{(_settings.CloseShellAfterPress ?
$" Write-Host '{notifyStr}'{addedCharacter}; [System.Console]::ReadKey(){addedCharacter}; exit" :
"")}");
break;
}

Expand Down Expand Up @@ -369,11 +389,11 @@
{
if (keyevent == (int)KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
{
_winRStroked = true;

Check warning on line 392 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`RStroked` is not a recognized word. (unrecognized-spelling)
OnWinRPressed();
return false;
}
if (keyevent == (int)KeyEvent.WM_KEYUP && _winRStroked && vkcode == (int)Keys.LWin)

Check warning on line 396 in Plugins/Flow.Launcher.Plugin.Shell/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`RStroked` is not a recognized word. (unrecognized-spelling)
{
_winRStroked = false;
_keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
Expand Down
Loading