Skip to content
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

Exit code does not work in PowerShell #849

Closed
2 tasks done
krzysdz opened this issue Jul 11, 2021 · 2 comments
Closed
2 tasks done

Exit code does not work in PowerShell #849

krzysdz opened this issue Jul 11, 2021 · 2 comments

Comments

@krzysdz
Copy link
Contributor

krzysdz commented Jul 11, 2021

Prerequisites

  • I have read and understood the CONTRIBUTING guide
  • I have looked for duplicate issues before submitting this one

Description

After 9576e82 exit code detection stopped working in PowerShell and success is always signalled, because $? is captured too late.

Moving the lines 78-79 to the top of the ScriptBlock solves the problem.

$omp = "::OMP::"
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
if ($global:PoshSettings.Transient -eq $true) {
$standardOut = @(&$omp --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" --print-transient 2>&1)
$standardOut -join "`n"
$global:PoshSettings.Transient = $false
return
}
#store if the last command was successful
$lastCommandSuccess = $?

Environment

  • Oh My Posh version: 3.168.2 / 3.166.3
  • Theme: slimfat
  • Operating System: Windows 10 21H1 / Windows 11 (22000.65 co_release)
  • Shell: PowerShell 7.1.3
  • Terminal: Windows Terminal Dev / Preview

Optional

  • posh-git version: 1.0.0
  • git version: 2.32.0.windows.2

Steps to Reproduce

  1. Select a theme with exit code. I used slimfat.
  2. Execute command exiting with 0.
  3. Execute command exiting with something other than 0, e.g. python -c "exit(1)".

Expected behavior:

Appropriate exit status and code are shown.

Exit code 0 after program exited with 0 and red exit code 1 after program exited with 1

Actual behavior:

Success is always shown, regardless of the exit code.

After executing python -c "exit(1)" success is reported (green indicator) and no error code is shown, even though $LASTEXITCODE is 1

@JanDeDobbeleer
Copy link
Owner

@krzysdz absolutely right. I'm an idiot.

Copy link

github-actions bot commented Apr 8, 2024

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants