Skip to content

Commit 09b90d1

Browse files
committed
Fix remote prompt ComputerName display
This change fixes the ComputerName prefix for prompts shown in remote sessions. Recent changes caused it to be lost.
1 parent aaad6f3 commit 09b90d1

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/PowerShellEditorServices/Console/ConsoleService.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
namespace Microsoft.PowerShell.EditorServices.Console
1212
{
13+
using Microsoft.PowerShell.EditorServices.Session;
1314
using System;
15+
using System.Globalization;
1416
using System.Management.Automation;
1517
using System.Security;
1618

@@ -264,10 +266,23 @@ public async Task<SecureString> ReadSecureLine(CancellationToken cancellationTok
264266

265267
private void WritePromptStringToHost()
266268
{
269+
string promptString = this.powerShellContext.PromptString;
270+
271+
// Update the stored prompt string if the session is remote
272+
if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Remote)
273+
{
274+
promptString =
275+
string.Format(
276+
CultureInfo.InvariantCulture,
277+
"[{0}]: {1}",
278+
this.powerShellContext.CurrentRunspace.Runspace.ConnectionInfo != null
279+
? this.powerShellContext.CurrentRunspace.Runspace.ConnectionInfo.ComputerName
280+
: this.powerShellContext.CurrentRunspace.SessionDetails.ComputerName,
281+
promptString);
282+
}
283+
267284
// Write the prompt string
268-
this.WriteOutput(
269-
this.powerShellContext.PromptString,
270-
false);
285+
this.WriteOutput(promptString, false);
271286
}
272287

273288
private void WriteDebuggerBanner(DebuggerStopEventArgs eventArgs)

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,17 +1367,6 @@ private SessionDetails GetSessionDetailsInRunspace(Runspace runspace)
13671367
}
13681368
});
13691369

1370-
if (this.CurrentRunspace != null &&
1371-
this.CurrentRunspace.Location == RunspaceLocation.Remote)
1372-
{
1373-
sessionDetails.PromptString =
1374-
string.Format(
1375-
CultureInfo.InvariantCulture,
1376-
"[{0}]: {1}",
1377-
runspace.ConnectionInfo.ComputerName,
1378-
sessionDetails.PromptString);
1379-
}
1380-
13811370
return sessionDetails;
13821371
}
13831372

0 commit comments

Comments
 (0)