Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<system:String x:Key="flowlauncher_plugin_cmd_press_any_key_to_close">Press any key to close this window...</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">Do not close Command Prompt after command execution</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Always run as administrator</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_use_windows_terminal">Use Windows Terminal</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Run as different user</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_plugin_name">Shell</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_plugin_description">Allows to execute system commands from Flow Launcher</system:String>
Expand All @@ -15,4 +16,4 @@
<system:String x:Key="flowlauncher_plugin_cmd_run_as_administrator">Run As Administrator</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_copy">Copy the command</system:String>
<system:String x:Key="flowlauncher_plugin_cmd_history">Only show number of most used commands:</system:String>
</ResourceDictionary>
</ResourceDictionary>
50 changes: 30 additions & 20 deletions Plugins/Flow.Launcher.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,31 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
{
case Shell.Cmd:
{
info.FileName = "cmd.exe";
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command} {(_settings.CloseShellAfterPress ? $"&& echo {context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")} && pause > nul /c" : "")}";

//// 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 separated correctly:
//// Incorrect:
// info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c");
// 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
if (_settings.UseWindowsTerminal)
{
info.FileName = "wt.exe";
info.ArgumentList.Add("cmd");
}
else
{
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" : "")}");
break;
}

case Shell.Powershell:
{
info.FileName = "powershell.exe";
if (_settings.UseWindowsTerminal)
{
info.FileName = "wt.exe";
info.ArgumentList.Add("powershell");
}
else
{
info.FileName = "powershell.exe";
}
if (_settings.LeaveShellOpen)
{
info.ArgumentList.Add("-NoExit");
Expand All @@ -232,21 +235,28 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
else
{
info.ArgumentList.Add("-Command");
info.ArgumentList.Add($"{command}; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'; [System.Console]::ReadKey(); exit" : "")}");
info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}");
}
break;
}

case Shell.Pwsh:
{
info.FileName = "pwsh.exe";
if (_settings.UseWindowsTerminal)
{
info.FileName = "wt.exe";
info.ArgumentList.Add("pwsh");
}
else
{
info.FileName = "pwsh.exe";
}
if (_settings.LeaveShellOpen)
{
info.ArgumentList.Add("-NoExit");
}
info.ArgumentList.Add("-Command");
info.ArgumentList.Add($"{command}; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'; [System.Console]::ReadKey(); exit" : "")}");

info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}");
break;
}

Expand Down
2 changes: 2 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Shell/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Settings

public bool RunAsAdministrator { get; set; } = true;

public bool UseWindowsTerminal { get; set; } = false;

public bool ShowOnlyMostUsedCMDs { get; set; }

public int ShowOnlyMostUsedCMDsNumber { get; set; }
Expand Down
11 changes: 9 additions & 2 deletions Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<CheckBox
x:Name="ReplaceWinR"
Expand All @@ -41,17 +42,23 @@
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="{DynamicResource flowlauncher_plugin_cmd_always_run_as_administrator}" />
<CheckBox
x:Name="UseWindowsTerminal"
Grid.Row="4"
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="{DynamicResource flowlauncher_plugin_cmd_use_windows_terminal}" />
<ComboBox
x:Name="ShellComboBox"
Grid.Row="4"
Grid.Row="5"
Margin="10,5,5,5"
HorizontalAlignment="Left">
<ComboBoxItem>CMD</ComboBoxItem>
<ComboBoxItem>PowerShell</ComboBoxItem>
<ComboBoxItem>Pwsh</ComboBoxItem>
<ComboBoxItem>RunCommand</ComboBoxItem>
</ComboBox>
<StackPanel Grid.Row="5" Orientation="Horizontal">
<StackPanel Grid.Row="6" Orientation="Horizontal">
<CheckBox
x:Name="ShowOnlyMostUsedCMDs"
Margin="10,5,5,5"
Expand Down
12 changes: 12 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;

AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator;

UseWindowsTerminal.IsChecked = _settings.UseWindowsTerminal;

LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;

Expand Down Expand Up @@ -76,6 +78,16 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
_settings.RunAsAdministrator = false;
};

UseWindowsTerminal.Checked += (o, e) =>
{
_settings.UseWindowsTerminal = true;
};

UseWindowsTerminal.Unchecked += (o, e) =>
{
_settings.UseWindowsTerminal = false;
};

ReplaceWinR.Checked += (o, e) =>
{
_settings.ReplaceWinR = true;
Expand Down
Loading