Skip to content

Commit 14029ee

Browse files
authored
Merge pull request #378 from PowerShell/daviwil/fix-remote-prompt
Fix remote prompt ComputerName display
2 parents aaad6f3 + 09b90d1 commit 14029ee

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/PowerShellEditorServices/Console/ConsoleService.cs

+18-3
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

-11
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)