From e6baa88002290203d099772e33a2d2f453328146 Mon Sep 17 00:00:00 2001 From: Ioannis G Date: Mon, 12 Jun 2023 15:49:33 +0300 Subject: [PATCH 1/2] decouple Shell from the ComboBox SelectedIndex enables us to add new `Shell` options without messing with the user's saved settings, while keeping the `RunCommand` option last. --- .../ShellSetting.xaml.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs index 749e9ec80c9..f4e8229b7e4 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Windows; using System.Windows.Controls; @@ -68,10 +68,21 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re) _settings.ReplaceWinR = false; }; - ShellComboBox.SelectedIndex = (int) _settings.Shell; + ShellComboBox.SelectedIndex = _settings.Shell switch + { + Shell.Cmd => 0, + Shell.Powershell => 1, + _ => ShellComboBox.Items.Count - 1 + }; + ShellComboBox.SelectionChanged += (o, e) => { - _settings.Shell = (Shell) ShellComboBox.SelectedIndex; + _settings.Shell = ShellComboBox.SelectedIndex switch + { + 0 => Shell.Cmd, + 1 => Shell.Powershell, + _ => Shell.RunCommand + }; LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand; }; From c6a6c6bd5c2f5fd6f93776ac1ad6487de7c961f5 Mon Sep 17 00:00:00 2001 From: Ioannis G Date: Mon, 12 Jun 2023 16:18:23 +0300 Subject: [PATCH 2/2] plugin/shell: add powershell core (pwsh) option Co-authored-by: shobu13 --- Plugins/Flow.Launcher.Plugin.Shell/Main.cs | 13 +++++++++++++ Plugins/Flow.Launcher.Plugin.Shell/Settings.cs | 2 +- .../Flow.Launcher.Plugin.Shell/ShellSetting.xaml | 1 + .../Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs | 4 +++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs index 24d263578bc..66917d59413 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Main.cs @@ -237,6 +237,19 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin break; } + case Shell.Pwsh: + { + info.FileName = "pwsh.exe"; + if (_settings.LeaveShellOpen) + { + info.ArgumentList.Add("-NoExit"); + } + info.ArgumentList.Add("-Command"); + info.ArgumentList.Add(command); + + break; + } + case Shell.RunCommand: { var parts = command.Split(new[] diff --git a/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs b/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs index a3cac1cb873..47b46055c7b 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/Settings.cs @@ -36,6 +36,6 @@ public enum Shell Cmd = 0, Powershell = 1, RunCommand = 2, - + Pwsh = 3, } } diff --git a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml index 39fb21c59cb..240bda95365 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml +++ b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml @@ -41,6 +41,7 @@ HorizontalAlignment="Left"> CMD PowerShell + Pwsh RunCommand diff --git a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs index f4e8229b7e4..ebb47dd1513 100644 --- a/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Windows; using System.Windows.Controls; @@ -72,6 +72,7 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re) { Shell.Cmd => 0, Shell.Powershell => 1, + Shell.Pwsh => 2, _ => ShellComboBox.Items.Count - 1 }; @@ -81,6 +82,7 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re) { 0 => Shell.Cmd, 1 => Shell.Powershell, + 2 => Shell.Pwsh, _ => Shell.RunCommand }; LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;