mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
Pt run] keep shell open (#28041)
* [PTRun] LeaveShellOpen condition added to run command * [PTRun] Keep shell open added to shell plugin settings. * [PTRun] Unnecessary variable deleted. Formatting. * [PTRun] Variable name changed.
This commit is contained in:
@@ -13,6 +13,8 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
|
using Microsoft.Plugin.Shell.Properties;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Plugin.Common;
|
using Wox.Plugin.Common;
|
||||||
@@ -21,7 +23,7 @@ using Control = System.Windows.Controls.Control;
|
|||||||
|
|
||||||
namespace Microsoft.Plugin.Shell
|
namespace Microsoft.Plugin.Shell
|
||||||
{
|
{
|
||||||
public class Main : IPlugin, IPluginI18n, IContextMenu, ISavable
|
public class Main : IPlugin, IPluginI18n, ISettingProvider, IContextMenu, ISavable
|
||||||
{
|
{
|
||||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||||
private static readonly IPath Path = FileSystem.Path;
|
private static readonly IPath Path = FileSystem.Path;
|
||||||
@@ -37,6 +39,16 @@ namespace Microsoft.Plugin.Shell
|
|||||||
|
|
||||||
public string Description => Properties.Resources.wox_plugin_cmd_plugin_description;
|
public string Description => Properties.Resources.wox_plugin_cmd_plugin_description;
|
||||||
|
|
||||||
|
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
|
||||||
|
{
|
||||||
|
new PluginAdditionalOption()
|
||||||
|
{
|
||||||
|
Key = "LeaveShellOpen",
|
||||||
|
DisplayLabel = Resources.wox_leave_shell_open,
|
||||||
|
Value = _settings.LeaveShellOpen,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
private PluginInitContext _context;
|
private PluginInitContext _context;
|
||||||
|
|
||||||
public Main()
|
public Main()
|
||||||
@@ -220,17 +232,41 @@ namespace Microsoft.Plugin.Shell
|
|||||||
if (ExistInPath(filename))
|
if (ExistInPath(filename))
|
||||||
{
|
{
|
||||||
var arguments = parts[1];
|
var arguments = parts[1];
|
||||||
info = ShellCommand.SetProcessStartInfo(filename, workingDirectory, arguments, runAsVerbArg);
|
if (_settings.LeaveShellOpen)
|
||||||
|
{
|
||||||
|
// Wrap the command in a cmd.exe process
|
||||||
|
info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, $"/k \"{filename} {arguments}\"", runAsVerbArg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info = ShellCommand.SetProcessStartInfo(filename, workingDirectory, arguments, runAsVerbArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_settings.LeaveShellOpen)
|
||||||
|
{
|
||||||
|
// Wrap the command in a cmd.exe process
|
||||||
|
info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, $"/k \"{command}\"", runAsVerbArg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info = ShellCommand.SetProcessStartInfo(command, verb: runAsVerbArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_settings.LeaveShellOpen)
|
||||||
|
{
|
||||||
|
// Wrap the command in a cmd.exe process
|
||||||
|
info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, $"/k \"{command}\"", runAsVerbArg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
info = ShellCommand.SetProcessStartInfo(command, verb: runAsVerbArg);
|
info = ShellCommand.SetProcessStartInfo(command, verb: runAsVerbArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
info = ShellCommand.SetProcessStartInfo(command, verb: runAsVerbArg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -378,5 +414,19 @@ namespace Microsoft.Plugin.Shell
|
|||||||
|
|
||||||
return resultlist;
|
return resultlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateSettings(PowerLauncherPluginSettings settings)
|
||||||
|
{
|
||||||
|
var leaveShellOpen = false;
|
||||||
|
|
||||||
|
if (settings != null && settings.AdditionalOptions != null)
|
||||||
|
{
|
||||||
|
var optionLeaveShellOpen = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "LeaveShellOpen");
|
||||||
|
leaveShellOpen = optionLeaveShellOpen?.Value ?? leaveShellOpen;
|
||||||
|
_settings.LeaveShellOpen = leaveShellOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,15 @@ namespace Microsoft.Plugin.Shell.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Keep shell open.
|
||||||
|
/// </summary>
|
||||||
|
public static string wox_leave_shell_open {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_leave_shell_open", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to this command has been executed {0} times.
|
/// Looks up a localized string similar to this command has been executed {0} times.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -141,4 +141,7 @@
|
|||||||
<data name="wox_plugin_cmd_run_as_user" xml:space="preserve">
|
<data name="wox_plugin_cmd_run_as_user" xml:space="preserve">
|
||||||
<value>Run as different user (Ctrl+Shift+U)</value>
|
<value>Run as different user (Ctrl+Shift+U)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="wox_leave_shell_open" xml:space="preserve">
|
||||||
|
<value>Keep shell open</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
Reference in New Issue
Block a user