-
Notifications
You must be signed in to change notification settings - Fork 166
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
PowerShell Snippet adds unwanted Backslash Character to Prompt #597
Comments
Hmm... this is a weird issue. @zadjii-msft -- any thoughts? |
Yea I need to update that snippet. Clearly, I don't use pwsh as my daily driver. I have a much more elaborate pwsh prompt I've been testing lately. I need to take this, and boil it down: $loc = $($executionContext.SessionState.Path.CurrentLocation);
# IMPORTANT: Make sure there's a printable charater _last_ in the prompt.
# Otherwise, PSReadline is gonna use the terminating `\` here and colorize
# that if it detects a syntax error
$out += "`e]133;A$([char]07)";
$out += "`e]9;9;`"$loc`"$([char]07)";
$out += "PWSH $loc$('>' * ($nestedPromptLevel + 1)) ";
$out += "`e]133;B$([char]07)";
$Global:__LastHistoryId = $LastHistoryEntry.Id
return $out
All the |
@zadjii-msft - Just wondering about this snippet issue... should I update the doc with your code above? Or have you had a chance to try boiling it down? Would love to get this resolved when you have a spare moment. |
This looks like a PowerShell issue, as I can reproduce it even on Linux (Konsole). See PowerShell/PSReadLine#3719. |
PSReadLine cuts a substring since the last non-whitespace character in the prompt as the error prompt [1], which is displayed when there are syntax errors. As a result, when the prompt ends in `$([char]27)\`, as in the previous example, an unexpected backslash may appear. See: PowerShell/PSReadLine#3719 [1] https://github.com/PowerShell/PSReadLine/blob/v2.2.6/PSReadLine/ReadLine.cs#L819. --- Closes #597
In the section PowerShell: powershell.exe or pwsh.exe, this code snippet is shown:
When I put it in my PowerShell Profile and open a new PowerShell window, an unwanted backslash character is added to the command prompt when typing. (In pure PowerShell and also in Windows Terminal)
It is shown, but not interpreted.
Example:
PS C:\Users\xxx\somedir>\$x=
The backslash appears as soon as the equal sign is typed, but also (seemingly) randomly.
I first thought the backslash in this line was at fault, but removing it causes an exception:
$out += "$([char]27)]9;9;`"$loc`"$([char]27)\"
Windows Terminal Version: 1.15.2712.0
$PSVersionTable:
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: