fix(zsh): use global scope for typeset to support lazy loading#2776
Open
losinggeneration wants to merge 1 commit intoantinomyhq:mainfrom
Open
fix(zsh): use global scope for typeset to support lazy loading#2776losinggeneration wants to merge 1 commit intoantinomyhq:mainfrom
losinggeneration wants to merge 1 commit intoantinomyhq:mainfrom
Conversation
The usage of typeset within zsh's scope rules means that if the
eval "$(forge zsh plugin)" is run within a function, the typeset's will
be function local scoped. However, forge expects these to be globally
scoped. This can be fixed by specifying typeset -g to be global instead
of scoped to whatever scope it currently is.
With this fixed, it would allow lazy loading plugin managers to work, or
in my case, by manually wrapping the forge initialization into
a function:
forge_ai() {
if [[ -z "$_FORGE_PLUGIN_LOADED" ]]; then
eval "$(forge zsh plugin)"
fi
}
This allows me to load forge when I want to, instead of it being always
initialized on startup.
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.
The usage of typeset within zsh's scope rules means that if the eval "$(forge zsh plugin)" is run within a function, the typesets will be function local scoped. However, forge expects these to be globally scoped. This can be fixed by specifying
typeset -gto be global instead of scoped to whatever scope it currently is.With this fixed, it would allow lazy loading plugin managers to work, or in my case, by manually wrapping the forge initialization into a function:
This allows me to load forge when I want to, instead of it being always initialized on startup.
Most of the typesets are regular arrays, however, zsh-syntax-highlighting's
ZSH_HIGHLIGHT_PATTERNSis an associative array, so we need to use -gA instead for that variable.Reverts #2770