Skip to content

PowerShell Terminal Integration script breaks scripts that use $? or $LastExitCode #165022

@Jaykul

Description

@Jaykul

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.73.0-insider
  • OS Version: Windows_NT x64 10.0.22623

Steps to Reproduce:

  1. With the integration set to manual
  2. Create a prompt that changes if the previous command has an error LastExitCode. E.g.
function prompt {"$(!$? ? "`e[41m$LastExitCode`e[49m " : '' )`e[36m$($MyInvocation.HistoryId)`e[35m $pwd`e[0m`n"}
  1. Run a command that sets it to show it works
git nosuchverb
  1. Run the vscode integration script:
.(code-insiders --locate-shell-integration-path pwsh)

or

.(code --locate-shell-integration-path pwsh)
  1. Rerun the error command
git nosuchverb

image

To fix this:

  1. Don't set the $LastExitCode variable. It's special
  2. If the last command wasn't successful, make sure the command before the original prompt is run isn't successful.

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugconfirmedIssue has been confirmed by VS Code Team memberinsiders-releasedPatch has been released in VS Code Insidersterminal-shell-pwshAn issue in the terminal specific to PowerShell, including shell integrationverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions