mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
**WARNING:** This PR will probably blow up all in-flight PRs at some point in the early days of CmdPal, two of us created seperate `Exts` and `exts` dirs. Depending on what the casing was on the branch that you checked one of those out from, it'd get stuck like that on your PC forever. Windows didn't care, so we never noticed. But GitHub does care, and now browsing the source on GitHub is basically impossible. Closes #38081
55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.CmdPal.Ext.Apps.Properties;
|
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
|
|
|
namespace Microsoft.CmdPal.Ext.Apps.Commands;
|
|
|
|
internal sealed partial class OpenInConsoleCommand : InvokableCommand
|
|
{
|
|
private static readonly IconInfo TheIcon = new("\ue838");
|
|
|
|
private readonly string _target;
|
|
|
|
public OpenInConsoleCommand(string target)
|
|
{
|
|
Name = Resources.open_path_in_console;
|
|
Icon = TheIcon;
|
|
|
|
_target = target;
|
|
}
|
|
|
|
internal static async Task LaunchTarget(string t)
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
try
|
|
{
|
|
var processStartInfo = new ProcessStartInfo
|
|
{
|
|
WorkingDirectory = t,
|
|
FileName = "cmd.exe",
|
|
};
|
|
|
|
Process.Start(processStartInfo);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Log.Exception($"Failed to open {Name} in console, {e.Message}", e, GetType());
|
|
}
|
|
});
|
|
}
|
|
|
|
public override CommandResult Invoke()
|
|
{
|
|
_ = LaunchTarget(_target).ConfigureAwait(false);
|
|
|
|
return CommandResult.Dismiss();
|
|
}
|
|
}
|