From f0b31631d295b0623bc440016ed0aba3c7c49dde Mon Sep 17 00:00:00 2001 From: Marshall Porter Date: Fri, 23 Oct 2026 18:27:58 -0700 Subject: [PATCH] PowerShell: keep $LASTEXITCODE across the prompt hook (#1342) Co-authored-by: Ajeet D'Souza <98ajeet@gmail.com> --- CHANGELOG.md | 1 + templates/powershell.txt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de4c2ca..abc4dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Nushell: `z` now handles relative paths through symlinked directories. - POSIX: fix `z` failing to enter directories whose names start with `-`. - Build: fix compilation failing when the source directory is read-only. +- PowerShell: the prompt hook no longer resets `$LASTEXITCODE`. ## [0.10.0] - 2026-07-04 diff --git a/templates/powershell.txt b/templates/powershell.txt index 37b60f4..a61866f 100644 --- a/templates/powershell.txt +++ b/templates/powershell.txt @@ -93,7 +93,9 @@ if ($global:__zoxide_hooked -ne 1) { if ($null -ne $__zoxide_prompt_old) { & $__zoxide_prompt_old } + $exitCode = Microsoft.PowerShell.Utility\Get-Variable LASTEXITCODE -Scope Global -ErrorAction Ignore -ValueOnly $null = __zoxide_hook + $global:LASTEXITCODE = $exitCode } } {%- endif %}