fix: do not use dynamic module in post-script for PowerShell #254
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the dynamic module used in a post-script for PowerShell exports a
prompt
function, which overrides the original. It also uses an environment variableNVS_ORIGINAL_PROMPT
to store the entire stringified originalprompt
function. However, there is a flaw: if the originalprompt
is defined inside a dynamic module as well, functions defined in that module will become inaccessible for$env:NVS_ORIGINAL_PROMPT
, which is invoked by the NVS-definedprompt
. This is caused by some "isolation" features of PowerShell modules. Related code:nvs/lib/auto.js
Lines 120 to 123 in bf45ef0
Related issue: JanDeDobbeleer/oh-my-posh#2568.
Since NVS is not a tool of prompt customization, it should respect the user's custom
prompt
function. As an alternative, we can save the originalprompt
in a global variable when we usenvs auto on
to enable the auto-switching so that it can be invoked/restored correctly. Also, we have to store the original$?
in another global variable which is accessible for the initialization script of a prompt customization tool and restore the original$global:LASTEXITCODE
after the auto-switching done so that the originalprompt
function can get the correct error code.❤️ Special thanks to @possum-enjoyer for the help and comments in #253.