Skip to content

Commit 17871a9

Browse files
committed
Fix InvokePrompt for remote sessions
1 parent dc36a49 commit 17871a9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

PSReadLine/ReadLine.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,33 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null)
817817
Console.CursorLeft = 0;
818818
Console.CursorTop = _singleton._initialY;
819819

820+
var runspaceIsRemote = _singleton._mockableMethods.RunspaceIsRemote(_singleton._runspace);
821+
System.Management.Automation.PowerShell ps;
822+
if (!runspaceIsRemote)
823+
{
824+
ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
825+
}
826+
else
827+
{
828+
ps = System.Management.Automation.PowerShell.Create();
829+
ps.Runspace = _singleton._runspace;
830+
}
820831
string newPrompt;
821-
using (var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
832+
using (ps)
822833
{
823834
ps.AddCommand("prompt");
824835
var result = ps.Invoke<string>();
825836
newPrompt = result.Count == 1 ? result[0] : "PS>";
826837
}
838+
839+
if (runspaceIsRemote)
840+
{
841+
var connectionInfo = _singleton._runspace.ConnectionInfo;
842+
if (!string.IsNullOrEmpty(connectionInfo.ComputerName))
843+
{
844+
newPrompt = string.Format(CultureInfo.InvariantCulture, "[{0}]: {1}", connectionInfo.ComputerName, newPrompt);
845+
}
846+
}
827847
Console.Write(newPrompt);
828848

829849
_singleton._initialX = Console.CursorLeft;

0 commit comments

Comments
 (0)