Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch from SSH widget to Terminal if available #3730

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions extensions/CoreWidgetProvider/Widgets/SSHWalletWidget.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Text.Json;
Expand Down Expand Up @@ -149,12 +150,26 @@ private void HandleConnect(WidgetActionInvokedArgs args)
var cmd = new Process();
cmd.StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/k \"ssh {args.Data}\"",
FileName = "wt.exe",
Arguments = $"ssh {args.Data}",
Comment on lines +153 to +154
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FileName = "wt.exe",
Arguments = $"ssh {args.Data}",
FileName = "ssh.exe",
Arguments = $"{args.Data}",

(then you cam probably also drop the fallback below)

This will let the OS spawn ssh in the user's default terminal app, regardless of if it's set to Terminal or conhost.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original change from cmd to wt, I got to remove the /k switch that keeps the window open. Do you know if there's something I can pass into ssh.exe to do the same thing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. That's a good question. The terminal has the closeOnExit setting, which is perfect for keeping the window open when ssh disconnects, but that isn't going to help conhost at all.

I suppose you could always just run cmd /k ssh {{whatever}}. Launching cmd directly will do the same thing - boot into whatever your default terminal is.

In my totally biased opinion though, I'd just launch ssh.exe directly. If the users want the console window to stay open after the session disconnects, then "here's a nickel kid, go get yourself a modern Terminal (and stop using conhost)"

UseShellExecute = true,
};

cmd.Start();
try
{
cmd.Start();
}
catch (Win32Exception win32Ex)
{
Log.Error(win32Ex, "Failed to start wt.exe. Falling back to cmd.exe.");
cmd.StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/k \"ssh {args.Data}\"",
UseShellExecute = true,
};
cmd.Start();
}
}

private void HandleCheckPath(WidgetActionInvokedArgs args)
Expand Down
Loading