Skip to content

Commit 5bb3d72

Browse files
committed
Use a checkbox instead of separate entries
1 parent 3596a77 commit 5bb3d72

File tree

7 files changed

+57
-58
lines changed

7 files changed

+57
-58
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/Languages/es-419.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<system:String x:Key="flowlauncher_plugin_cmd_press_any_key_to_close">Press any key to close this window...</system:String>
77
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">No cerrar Símbolo del Sistema tras ejecutar el comando</system:String>
88
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Siempre ejecutar como administrador</system:String>
9+
<system:String x:Key="flowlauncher_plugin_cmd_always_use_windows_terminal">Ejecutar en la Terminal de Windows</system:String>
910
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Ejecutar como otro usuario</system:String>
1011
<system:String x:Key="flowlauncher_plugin_cmd_plugin_name">Shell</system:String>
1112
<system:String x:Key="flowlauncher_plugin_cmd_plugin_description">Allows to execute system commands from Flow Launcher</system:String>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<system:String x:Key="flowlauncher_plugin_cmd_press_any_key_to_close">Pulsar cualquier tecla para cerrar esta ventana...</system:String>
77
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">No cerrar el símbolo del sistema después de la ejecución del comando</system:String>
88
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Ejecutar siempre como administrador</system:String>
9+
<system:String x:Key="flowlauncher_plugin_cmd_always_use_windows_terminal">Ejecutar en la Terminal de Windows</system:String>
910
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Ejecutar como usuario diferente</system:String>
1011
<system:String x:Key="flowlauncher_plugin_cmd_plugin_name">Terminal</system:String>
1112
<system:String x:Key="flowlauncher_plugin_cmd_plugin_description">Permite ejecutar comandos del sistema desde Flow Launcher</system:String>

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

Lines changed: 30 additions & 47 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

@@ -279,33 +289,6 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
279289

280290
break;
281291
}
282-
case Shell.TerminalPWSH:
283-
{
284-
info.FileName = "wt.exe";
285-
info.ArgumentList.Add("pwsh");
286-
if (_settings.LeaveShellOpen)
287-
{
288-
info.ArgumentList.Add("-NoExit");
289-
}
290-
info.ArgumentList.Add("-Command");
291-
info.ArgumentList.Add(command);
292-
break;
293-
}
294-
case Shell.TerminalCMD:
295-
{
296-
info.FileName = "wt.exe";
297-
info.ArgumentList.Add("cmd");
298-
if (_settings.LeaveShellOpen)
299-
{
300-
info.ArgumentList.Add("/k");
301-
}
302-
else
303-
{
304-
info.ArgumentList.Add("/c");
305-
}
306-
info.ArgumentList.Add(command);
307-
break;
308-
}
309292
default:
310293
throw new NotImplementedException();
311294
}

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

Lines changed: 2 additions & 2 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; }
@@ -39,7 +41,5 @@ public enum Shell
3941
Powershell = 1,
4042
RunCommand = 2,
4143
Pwsh = 3,
42-
TerminalPWSH = 4,
43-
TerminalCMD = 5,
4444
}
4545
}

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

Lines changed: 9 additions & 4 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,19 +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>
52-
<ComboBoxItem>Terminal (Pwsh)</ComboBoxItem>
53-
<ComboBoxItem>Terminal (CMD)</ComboBoxItem>
5459
<ComboBoxItem>RunCommand</ComboBoxItem>
5560
</ComboBox>
56-
<StackPanel Grid.Row="5" Orientation="Horizontal">
61+
<StackPanel Grid.Row="6" Orientation="Horizontal">
5762
<CheckBox
5863
x:Name="ShowOnlyMostUsedCMDs"
5964
Margin="10,5,5,5"

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

Lines changed: 12 additions & 4 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;
@@ -91,8 +103,6 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
91103
Shell.Cmd => 0,
92104
Shell.Powershell => 1,
93105
Shell.Pwsh => 2,
94-
Shell.TerminalPWSH => 3,
95-
Shell.TerminalCMD => 4,
96106
_ => ShellComboBox.Items.Count - 1
97107
};
98108

@@ -103,8 +113,6 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
103113
0 => Shell.Cmd,
104114
1 => Shell.Powershell,
105115
2 => Shell.Pwsh,
106-
3 => Shell.TerminalPWSH,
107-
4 => Shell.TerminalCMD,
108116
_ => Shell.RunCommand
109117
};
110118
LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand;

0 commit comments

Comments
 (0)