Skip to content

fix(zsh): use global scope for typeset to support lazy loading#2776

Open
losinggeneration wants to merge 1 commit intoantinomyhq:mainfrom
losinggeneration:fix/zsh-lazy-loading
Open

fix(zsh): use global scope for typeset to support lazy loading#2776
losinggeneration wants to merge 1 commit intoantinomyhq:mainfrom
losinggeneration:fix/zsh-lazy-loading

Conversation

@losinggeneration
Copy link
Copy Markdown
Contributor

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 -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.

Most of the typesets are regular arrays, however, zsh-syntax-highlighting's ZSH_HIGHLIGHT_PATTERNS is an associative array, so we need to use -gA instead for that variable.

Reverts #2770

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.
@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant