Skip to content

Commit 4add7e1

Browse files
authored
Revert "fix(zsh): use global scope for typeset to support lazy loading" (#2810)
1 parent b1054bd commit 4add7e1

File tree

4 files changed

+19
-35
lines changed

4 files changed

+19
-35
lines changed

crates/forge_main/src/zsh/plugin.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ pub fn generate_zsh_plugin() -> Result<String> {
4444
output.push_str(&completions_str);
4545

4646
// Set environment variable to indicate plugin is loaded (with timestamp)
47-
// Use typeset -g so the variable is global even when eval'd inside a function
48-
// (e.g. lazy-loading plugin managers like zinit, zplug, zsh-defer)
49-
output.push_str("\ntypeset -g _FORGE_PLUGIN_LOADED=$(date +%s)\n");
47+
output.push_str("\n_FORGE_PLUGIN_LOADED=$(date +%s)\n");
5048

5149
Ok(output)
5250
}
@@ -57,9 +55,7 @@ pub fn generate_zsh_theme() -> Result<String> {
5755
super::normalize_script(include_str!("../../../../shell-plugin/forge.theme.zsh"));
5856

5957
// Set environment variable to indicate theme is loaded (with timestamp)
60-
// Use typeset -g so the variable is global even when eval'd inside a function
61-
// (e.g. lazy-loading plugin managers like zinit, zplug, zsh-defer)
62-
content.push_str("\ntypeset -g _FORGE_THEME_LOADED=$(date +%s)\n");
58+
content.push_str("\n_FORGE_THEME_LOADED=$(date +%s)\n");
6359

6460
Ok(content)
6561
}

shell-plugin/forge.theme.zsh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env zsh
22

33
# Enable prompt substitution for RPROMPT
4-
# Use emulate to ensure setopt applies globally even when sourced from a function
5-
emulate -R zsh -c 'setopt PROMPT_SUBST'
4+
setopt PROMPT_SUBST
65

76
# Model and agent info with token count
87
# Fully formatted output directly from Rust
@@ -24,7 +23,6 @@ function _forge_prompt_info() {
2423

2524
# Right prompt: agent and model with token count (uses single forge prompt command)
2625
# Set RPROMPT if empty, otherwise append to existing value
27-
# Use typeset -g to ensure RPROMPT is set globally even when sourced from a function
2826
if [[ -z "$_FORGE_THEME_LOADED" ]]; then
29-
typeset -g RPROMPT='$(_forge_prompt_info)'"${RPROMPT:+ ${RPROMPT}}"
27+
RPROMPT='$(_forge_prompt_info)'"${RPROMPT:+ ${RPROMPT}}"
3028
fi

shell-plugin/lib/config.zsh

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
#!/usr/bin/env zsh
22

33
# Configuration variables for forge plugin
4-
# Using typeset -gh (global + hidden) so variables survive lazy-loading
5-
# from within a function scope (e.g. zinit, zplug, zsh-defer) while
6-
# staying hidden from `typeset` listings.
4+
# Using typeset to keep variables local to plugin scope and prevent public exposure
75

8-
typeset -gh _FORGE_BIN="${FORGE_BIN:-forge}"
9-
typeset -gh _FORGE_CONVERSATION_PATTERN=":"
10-
typeset -gh _FORGE_MAX_COMMIT_DIFF="${FORGE_MAX_COMMIT_DIFF:-100000}"
11-
typeset -gh _FORGE_DELIMITER='\s\s+'
12-
typeset -gh _FORGE_PREVIEW_WINDOW="--preview-window=bottom:75%:wrap:border-sharp"
6+
typeset -h _FORGE_BIN="${FORGE_BIN:-forge}"
7+
typeset -h _FORGE_CONVERSATION_PATTERN=":"
8+
typeset -h _FORGE_MAX_COMMIT_DIFF="${FORGE_MAX_COMMIT_DIFF:-100000}"
9+
typeset -h _FORGE_DELIMITER='\s\s+'
10+
typeset -h _FORGE_PREVIEW_WINDOW="--preview-window=bottom:75%:wrap:border-sharp"
1311

1412
# Detect fd command - Ubuntu/Debian use 'fdfind', others use 'fd'
15-
typeset -gh _FORGE_FD_CMD="$(command -v fdfind 2>/dev/null || command -v fd 2>/dev/null || echo 'fd')"
13+
typeset -h _FORGE_FD_CMD="$(command -v fdfind 2>/dev/null || command -v fd 2>/dev/null || echo 'fd')"
1614

1715
# Detect bat command - use bat if available, otherwise fall back to cat
1816
if command -v bat &>/dev/null; then
19-
typeset -gh _FORGE_CAT_CMD="bat --color=always --style=numbers,changes --line-range=:500"
17+
typeset -h _FORGE_CAT_CMD="bat --color=always --style=numbers,changes --line-range=:500"
2018
else
21-
typeset -gh _FORGE_CAT_CMD="cat"
19+
typeset -h _FORGE_CAT_CMD="cat"
2220
fi
2321

2422
# Commands cache - loaded lazily on first use
25-
typeset -gh _FORGE_COMMANDS=""
23+
typeset -h _FORGE_COMMANDS=""
2624

2725
# Hidden variables to be used only via the ForgeCLI
28-
typeset -gh _FORGE_CONVERSATION_ID
29-
typeset -gh _FORGE_ACTIVE_AGENT
26+
typeset -h _FORGE_CONVERSATION_ID
27+
typeset -h _FORGE_ACTIVE_AGENT
3028

3129
# Previous conversation ID for :conversation - (like cd -)
32-
typeset -gh _FORGE_PREVIOUS_CONVERSATION_ID
30+
typeset -h _FORGE_PREVIOUS_CONVERSATION_ID
3331

3432
# Session-scoped model and provider overrides (set via :model / :m).
3533
# When non-empty, these are passed as --model / --provider to every forge
3634
# invocation for the lifetime of the current shell session.
37-
typeset -gh _FORGE_SESSION_MODEL
38-
typeset -gh _FORGE_SESSION_PROVIDER
35+
typeset -h _FORGE_SESSION_MODEL
36+
typeset -h _FORGE_SESSION_PROVIDER

shell-plugin/lib/highlight.zsh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
# Syntax highlighting configuration for forge commands
44
# Style the conversation pattern with appropriate highlighting
55
# Keywords in yellow, rest in default white
6-
#
7-
# Use global declarations so we update the shared zsh-syntax-highlighting
8-
# collections even when sourced from within a function (lazy-loading plugin
9-
# managers). Patterns must remain an associative array because the pattern
10-
# highlighter stores regex => style entries in ZSH_HIGHLIGHT_PATTERNS.
11-
12-
typeset -gA ZSH_HIGHLIGHT_PATTERNS
13-
typeset -ga ZSH_HIGHLIGHT_HIGHLIGHTERS
146

157
# Style tagged files
168
ZSH_HIGHLIGHT_PATTERNS+=('@\[[^]]#\]' 'fg=cyan,bold')

0 commit comments

Comments
 (0)