Skip to content

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

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

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

Conversation

@losinggeneration
Copy link
Copy Markdown
Contributor

@losinggeneration losinggeneration commented Apr 3, 2026

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.

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.

Partially reverts: #2810
Since RPROMPT is a builtin, it gets special treatment and is always global. This means there's no need to modify the forge.theme.zsh as it works both lazy loaded or not. I've tested this with a minimal zshrc that only has forge zsh setup, and it works there.

@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 3, 2026
@tusharmath
Copy link
Copy Markdown
Collaborator

Appreciate your relentless efforts in making the ZSH experience better!

@losinggeneration losinggeneration marked this pull request as draft April 3, 2026 19:49
@losinggeneration losinggeneration marked this pull request as ready for review April 3, 2026 19:54
@losinggeneration losinggeneration force-pushed the fix/zsh-lazy-loading branch 3 times, most recently from 75eb2ef to f0901f9 Compare April 6, 2026 20:23
@github-actions
Copy link
Copy Markdown

Action required: PR inactive for 5 days.
Status update or closure in 10 days.

@github-actions github-actions bot added state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. and removed state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. labels Apr 12, 2026
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.

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

2 participants