Skip to content

Commit 06e3452

Browse files
Merge pull request #2410 from flooxo/shell_fix
New option CloseShellAfterPress
2 parents 1f99d0d + d0f2503 commit 06e3452

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
xmlns:system="clr-namespace:System;assembly=mscorlib">
44

55
<system:String x:Key="flowlauncher_plugin_cmd_relace_winr">Replace Win+R</system:String>
6+
<system:String x:Key="flowlauncher_plugin_cmd_close_cmd_after_press">Close Command Prompt after pressing any key</system:String>
7+
<system:String x:Key="flowlauncher_plugin_cmd_press_any_key_to_close">Press any key to close this window...</system:String>
68
<system:String x:Key="flowlauncher_plugin_cmd_leave_cmd_open">Do not close Command Prompt after command execution</system:String>
79
<system:String x:Key="flowlauncher_plugin_cmd_always_run_as_administrator">Always run as administrator</system:String>
810
<system:String x:Key="flowlauncher_plugin_cmd_run_as_different_user">Run as different user</system:String>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
203203
case Shell.Cmd:
204204
{
205205
info.FileName = "cmd.exe";
206-
info.Arguments = $"{(_settings.LeaveShellOpen ? "/k" : "/c")} {command}";
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" : "")}";
207207

208208
//// Use info.Arguments instead of info.ArgumentList to enable users better control over the arguments they are writing.
209209
//// Previous code using ArgumentList, commands needed to be separated correctly:
@@ -232,7 +232,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
232232
else
233233
{
234234
info.ArgumentList.Add("-Command");
235-
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" : "")}");
236236
}
237237
break;
238238
}
@@ -245,7 +245,7 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
245245
info.ArgumentList.Add("-NoExit");
246246
}
247247
info.ArgumentList.Add("-Command");
248-
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" : "")}");
249249

250250
break;
251251
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class Settings
77
public Shell Shell { get; set; } = Shell.Cmd;
88

99
public bool ReplaceWinR { get; set; } = false;
10+
11+
public bool CloseShellAfterPress { get; set; } = false;
1012

1113
public bool LeaveShellOpen { get; set; }
1214

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<RowDefinition />
1616
<RowDefinition />
1717
<RowDefinition />
18+
<RowDefinition />
1819
</Grid.RowDefinitions>
1920
<CheckBox
2021
x:Name="ReplaceWinR"
@@ -23,28 +24,34 @@
2324
HorizontalAlignment="Left"
2425
Content="{DynamicResource flowlauncher_plugin_cmd_relace_winr}" />
2526
<CheckBox
26-
x:Name="LeaveShellOpen"
27+
x:Name="CloseShellAfterPress"
2728
Grid.Row="1"
2829
Margin="10,5,5,5"
2930
HorizontalAlignment="Left"
31+
Content="{DynamicResource flowlauncher_plugin_cmd_close_cmd_after_press}" />
32+
<CheckBox
33+
x:Name="LeaveShellOpen"
34+
Grid.Row="2"
35+
Margin="10,5,5,5"
36+
HorizontalAlignment="Left"
3037
Content="{DynamicResource flowlauncher_plugin_cmd_leave_cmd_open}" />
3138
<CheckBox
3239
x:Name="AlwaysRunAsAdministrator"
33-
Grid.Row="2"
40+
Grid.Row="3"
3441
Margin="10,5,5,5"
3542
HorizontalAlignment="Left"
3643
Content="{DynamicResource flowlauncher_plugin_cmd_always_run_as_administrator}" />
3744
<ComboBox
3845
x:Name="ShellComboBox"
39-
Grid.Row="3"
46+
Grid.Row="4"
4047
Margin="10,5,5,5"
4148
HorizontalAlignment="Left">
4249
<ComboBoxItem>CMD</ComboBoxItem>
4350
<ComboBoxItem>PowerShell</ComboBoxItem>
4451
<ComboBoxItem>Pwsh</ComboBoxItem>
4552
<ComboBoxItem>RunCommand</ComboBoxItem>
4653
</ComboBox>
47-
<StackPanel Grid.Row="4" Orientation="Horizontal">
54+
<StackPanel Grid.Row="5" Orientation="Horizontal">
4855
<CheckBox
4956
x:Name="ShowOnlyMostUsedCMDs"
5057
Margin="10,5,5,5"

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public CMDSetting(Settings settings)
1717
private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
1818
{
1919
ReplaceWinR.IsChecked = _settings.ReplaceWinR;
20+
21+
CloseShellAfterPress.IsChecked = _settings.CloseShellAfterPress;
2022

2123
LeaveShellOpen.IsChecked = _settings.LeaveShellOpen;
2224

@@ -38,14 +40,30 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
3840
_settings.ShowOnlyMostUsedCMDsNumber = (int)ShowOnlyMostUsedCMDsNumber.SelectedItem;
3941
}
4042

43+
CloseShellAfterPress.Checked += (o, e) =>
44+
{
45+
_settings.CloseShellAfterPress = true;
46+
LeaveShellOpen.IsChecked = false;
47+
LeaveShellOpen.IsEnabled = false;
48+
};
49+
50+
CloseShellAfterPress.Unchecked += (o, e) =>
51+
{
52+
_settings.CloseShellAfterPress = false;
53+
LeaveShellOpen.IsEnabled = true;
54+
};
55+
4156
LeaveShellOpen.Checked += (o, e) =>
4257
{
4358
_settings.LeaveShellOpen = true;
59+
CloseShellAfterPress.IsChecked = false;
60+
CloseShellAfterPress.IsEnabled = false;
4461
};
4562

4663
LeaveShellOpen.Unchecked += (o, e) =>
4764
{
4865
_settings.LeaveShellOpen = false;
66+
CloseShellAfterPress.IsEnabled = true;
4967
};
5068

5169
AlwaysRunAsAdministrator.Checked += (o, e) =>

0 commit comments

Comments
 (0)