Skip to content

Commit 9917de9

Browse files
authored
Merge pull request #3225 from Azakidev/dev
Add Windows Terminal to Shell Plugins
2 parents e502ebc + 6084d07 commit 9917de9

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

Plugins/Flow.Launcher.Plugin.Shell/Languages/en.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<system:String x:Key="flowlauncher_plugin_cmd_press_any_key_to_close">Press any key to close this window...</system:String>
88
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">Do not close Command Prompt after command execution</system:String>
99
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Always run as administrator</system:String>
10+
<system:String x:Key="flowlauncher_plugin_cmd_use_windows_terminal">Use Windows Terminal</system:String>
1011
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Run as different user</system:String>
1112
<system:String x:Key="flowlauncher_plugin_cmd_plugin_name">Shell</system:String>
1213
<system:String x:Key="flowlauncher_plugin_cmd_plugin_description">Allows to execute system commands from Flow Launcher</system:String>
@@ -15,4 +16,4 @@
1516
<system:String x:Key="flowlauncher_plugin_cmd_run_as_administrator">Run As Administrator</system:String>
1617
<system:String x:Key="flowlauncher_plugin_cmd_copy">Copy the command</system:String>
1718
<system:String x:Key="flowlauncher_plugin_cmd_history">Only show number of most used commands:</system:String>
18-
</ResourceDictionary>
19+
</ResourceDictionary>

Plugins/Flow.Launcher.Plugin.Shell/Main.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,28 +202,31 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
202202
{
203203
case Shell.Cmd:
204204
{
205-
info.FileName = "cmd.exe";
206-
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command} {(_settings.CloseShellAfterPress ? $"&& echo {context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")} && pause > nul /c" : "")}";
207-
208-
//// Use info.Arguments instead of info.ArgumentList to enable users better control over the arguments they are writing.
209-
//// Previous code using ArgumentList, commands needed to be separated correctly:
210-
//// Incorrect:
211-
// info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c");
212-
// info.ArgumentList.Add(command); //<== info.ArgumentList.Add("mkdir \"c:\\test new\"");
213-
214-
//// Correct version should be:
215-
//info.ArgumentList.Add(_settings.LeaveShellOpen ? "/k" : "/c");
216-
//info.ArgumentList.Add("mkdir");
217-
//info.ArgumentList.Add(@"c:\test new");
218-
219-
//https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0#remarks
205+
if (_settings.UseWindowsTerminal)
206+
{
207+
info.FileName = "wt.exe";
208+
info.ArgumentList.Add("cmd");
209+
}
210+
else
211+
{
212+
info.FileName = "cmd.exe";
213+
}
220214

215+
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" : "")}");
221216
break;
222217
}
223218

224219
case Shell.Powershell:
225220
{
226-
info.FileName = "powershell.exe";
221+
if (_settings.UseWindowsTerminal)
222+
{
223+
info.FileName = "wt.exe";
224+
info.ArgumentList.Add("powershell");
225+
}
226+
else
227+
{
228+
info.FileName = "powershell.exe";
229+
}
227230
if (_settings.LeaveShellOpen)
228231
{
229232
info.ArgumentList.Add("-NoExit");
@@ -232,21 +235,28 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
232235
else
233236
{
234237
info.ArgumentList.Add("-Command");
235-
info.ArgumentList.Add($"{command}; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'; [System.Console]::ReadKey(); exit" : "")}");
238+
info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}");
236239
}
237240
break;
238241
}
239242

240243
case Shell.Pwsh:
241244
{
242-
info.FileName = "pwsh.exe";
245+
if (_settings.UseWindowsTerminal)
246+
{
247+
info.FileName = "wt.exe";
248+
info.ArgumentList.Add("pwsh");
249+
}
250+
else
251+
{
252+
info.FileName = "pwsh.exe";
253+
}
243254
if (_settings.LeaveShellOpen)
244255
{
245256
info.ArgumentList.Add("-NoExit");
246257
}
247258
info.ArgumentList.Add("-Command");
248-
info.ArgumentList.Add($"{command}; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'; [System.Console]::ReadKey(); exit" : "")}");
249-
259+
info.ArgumentList.Add($"{command}\\; {(_settings.CloseShellAfterPress ? $"Write-Host '{context.API.GetTranslation("flowlauncher_plugin_cmd_press_any_key_to_close")}'\\; [System.Console]::ReadKey()\\; exit" : "")}");
250260
break;
251261
}
252262

Plugins/Flow.Launcher.Plugin.Shell/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class Settings
1414

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

17+
public bool UseWindowsTerminal { get; set; } = false;
18+
1719
public bool ShowOnlyMostUsedCMDs { get; set; }
1820

1921
public int ShowOnlyMostUsedCMDsNumber { get; set; }

Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<RowDefinition />
1717
<RowDefinition />
1818
<RowDefinition />
19+
<RowDefinition />
1920
</Grid.RowDefinitions>
2021
<CheckBox
2122
x:Name="ReplaceWinR"
@@ -41,17 +42,23 @@
4142
Margin="10,5,5,5"
4243
HorizontalAlignment="Left"
4344
Content="{DynamicResource flowlauncher_plugin_cmd_always_run_as_administrator}" />
45+
<CheckBox
46+
x:Name="UseWindowsTerminal"
47+
Grid.Row="4"
48+
Margin="10,5,5,5"
49+
HorizontalAlignment="Left"
50+
Content="{DynamicResource flowlauncher_plugin_cmd_use_windows_terminal}" />
4451
<ComboBox
4552
x:Name="ShellComboBox"
46-
Grid.Row="4"
53+
Grid.Row="5"
4754
Margin="10,5,5,5"
4855
HorizontalAlignment="Left">
4956
<ComboBoxItem>CMD</ComboBoxItem>
5057
<ComboBoxItem>PowerShell</ComboBoxItem>
5158
<ComboBoxItem>Pwsh</ComboBoxItem>
5259
<ComboBoxItem>RunCommand</ComboBoxItem>
5360
</ComboBox>
54-
<StackPanel Grid.Row="5" Orientation="Horizontal">
61+
<StackPanel Grid.Row="6" Orientation="Horizontal">
5562
<CheckBox
5663
x:Name="ShowOnlyMostUsedCMDs"
5764
Margin="10,5,5,5"

Plugins/Flow.Launcher.Plugin.Shell/ShellSetting.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
2323
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;
2424

2525
AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator;
26+
27+
UseWindowsTerminal.IsChecked = _settings.UseWindowsTerminal;
2628

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

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

81+
UseWindowsTerminal.Checked += (o, e) =>
82+
{
83+
_settings.UseWindowsTerminal = true;
84+
};
85+
86+
UseWindowsTerminal.Unchecked += (o, e) =>
87+
{
88+
_settings.UseWindowsTerminal = false;
89+
};
90+
7991
ReplaceWinR.Checked += (o, e) =>
8092
{
8193
_settings.ReplaceWinR = true;

0 commit comments

Comments
 (0)