fix: do not use dynamic module in post-script for PowerShell - #254
Merged
Conversation
|
I can confirm this is working, as I've been using it for several weeks since I use posh-git and out of the box NVS was breaking my prompt when using |
jasongin
approved these changes
Dec 6, 2022
Owner
|
Thanks for the contribution! And sorry for the delay in merging. |
Owner
|
Released as nvs v1.7.0. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
promptfunction, which overrides the original. It also uses an environment variableNVS_ORIGINAL_PROMPTto store the entire stringified originalpromptfunction. However, there is a flaw: if the originalpromptis 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
promptfunction. As an alternative, we can save the originalpromptin a global variable when we usenvs auto onto 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:LASTEXITCODEafter the auto-switching done so that the originalpromptfunction can get the correct error code.❤️ Special thanks to @possum-enjoyer for the help and comments in #253.