File size: 23,578 Bytes
1244914
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
#!/usr/bin/env zsh

# ZSH Doctor - Diagnostic tool for Forge shell environment
# Checks for common configuration issues and environment setup

# Source user's .zshrc to get their environment (suppress errors from non-interactive mode)
if [[ -f "${ZDOTDIR:-$HOME}/.zshrc" ]]; then
    source "${ZDOTDIR:-$HOME}/.zshrc" 2>/dev/null
fi

# ANSI codes
local RESET='\033[0m'
local _BOLD='\033[1m'
local _DIM='\033[2m'
local _GREEN='\033[0;32m'
local _RED='\033[0;31m'
local _YELLOW='\033[0;33m'
local _CYAN='\033[0;36m'

# Text formatting helpers - auto-reset
function bold() { echo "${_BOLD}${1}${RESET}"; }
function dim() { echo "${_DIM}${1}${RESET}"; }
function green() { echo "${_GREEN}${1}${RESET}"; }
function red() { echo "${_RED}${1}${RESET}"; }
function yellow() { echo "${_YELLOW}${1}${RESET}"; }
function cyan() { echo "${_CYAN}${1}${RESET}"; }

# Simple ASCII symbols
local PASS="[OK]"
local FAIL="[ERROR]"
local WARN="[WARN]"

# Counters
local passed=0
local failed=0
local warnings=0

# Helper function to print section headers
function print_section() {
    echo ""
    echo "$(bold "$1")"
}

# Helper function to print results
function print_result() {
    local result_status=$1
    local message=$2
    local detail=$3
    
    case $result_status in
        pass)
            echo "  $(green "${PASS}") ${message}"
            ((passed++))
            ;;
        fail)
            echo "  $(red "${FAIL}") ${message}"
            [[ -n "$detail" ]] && echo "  $(dim "Β· ${detail}")"
            ((failed++))
            ;;
        warn)
            echo "  $(yellow "${WARN}") ${message}"
            [[ -n "$detail" ]] && echo "  $(dim "Β· ${detail}")"
            ((warnings++))
            ;;
        info)
            echo "  $(dim "Β· ${message}")"
            ;;
        code)
            echo "  $(dim "Β· ${message}")"
            ;;
        instruction)
            echo "  $(dim "Β· ${message}")"
            ;;
    esac
}

echo "$(bold "FORGE ENVIRONMENT DIAGNOSTICS")"

# 1. Check ZSH version
print_section "Shell Environment"
local zsh_version="${ZSH_VERSION}"
if [[ -n "$zsh_version" ]]; then
    local major=$(echo $zsh_version | cut -d. -f1)
    local minor=$(echo $zsh_version | cut -d. -f2)
    if [[ $major -ge 5 ]] && [[ $minor -ge 0 ]]; then
        print_result pass "zsh: ${zsh_version}"
    else
        print_result warn "zsh: ${zsh_version}" "Recommended: 5.0+"
    fi
else
    print_result fail "Unable to detect ZSH version"
fi

# Check terminal information
if [[ -n "$TERM_PROGRAM" ]]; then
    if [[ -n "$TERM_PROGRAM_VERSION" ]]; then
        print_result pass "Terminal: ${TERM_PROGRAM} ${TERM_PROGRAM_VERSION}"
    else
        print_result pass "Terminal: ${TERM_PROGRAM}"
    fi
elif [[ -n "$TERM" ]]; then
    print_result pass "Terminal: ${TERM}"
else
    print_result info "Terminal: unknown"
fi


# Check if Oh My Zsh is installed
if [[ -n "$ZSH" ]] && [[ -d "$ZSH" ]]; then
    local omz_version=""
    # Try to get OMZ version from version file if it exists
    if [[ -f "$ZSH/.git/refs/heads/master" ]]; then
        omz_version=$(cd "$ZSH" && git describe --tags 2>/dev/null || echo "custom")
    fi
    
    if [[ -n "$omz_version" ]]; then
        print_result pass "Oh My Zsh: ${omz_version}"
    else
        print_result pass "Oh My Zsh: installed"
    fi
    print_result info "${ZSH}"
else
    print_result warn "Oh My Zsh not found" "Install: sh -c \"\$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\""
fi

# 2. Check if forge is installed and in PATH
print_section "Forge Installation"

# Check if forge is in PATH
if command -v forge &> /dev/null; then
    local forge_path=$(command -v forge)
    
    # Get forge version and extract just the version number
    local forge_version=$(forge --version 2>&1 | head -n1 | awk '{print $2}')
    if [[ -n "$forge_version" ]]; then
        print_result pass "forge: ${forge_version}"
        print_result info "${forge_path}"
    else
        print_result pass "forge: installed"
        print_result info "${forge_path}"
    fi
else
    print_result fail "Forge binary not found in PATH" "Installation: curl -fsSL https://forgecode.dev/cli | sh"
fi

# 3. Check shell plugin
print_section "Plugin"

# Check if forge plugin is loaded by checking environment variable
if [[ -n "$_FORGE_PLUGIN_LOADED" ]]; then
    print_result pass "Forge plugin loaded"
else
    print_result fail "Forge plugin not loaded"
    print_result instruction "Add to your ~/.zshrc:"
    print_result code "eval \"\$(forge zsh plugin)\""
    print_result instruction "Or run: forge zsh setup"
fi


# Check plugin loading order in .zshrc
local zshrc_file="${ZDOTDIR:-$HOME}/.zshrc"
if [[ -f "$zshrc_file" ]] && [[ -n "$_FORGE_PLUGIN_LOADED" ]]; then
    # Extract line numbers for plugin declarations and forge plugin eval
    local plugins_line=$(grep -n "^[[:space:]]*plugins=(" "$zshrc_file" 2>/dev/null | head -n1 | cut -d: -f1)
    local forge_plugin_line=$(grep -n "eval.*forge.*zsh plugin" "$zshrc_file" 2>/dev/null | head -n1 | cut -d: -f1)

    if [[ -n "$plugins_line" ]] && [[ -n "$forge_plugin_line" ]]; then
        if [[ $forge_plugin_line -lt $plugins_line ]]; then
            print_result fail "Plugin loading order incorrect"
            print_result instruction "Forge plugin (line ${forge_plugin_line}) should be loaded AFTER plugins=() (line ${plugins_line})"
            print_result instruction "Move the forge plugin eval statement after the plugins=() array in ~/.zshrc"
        else
            print_result pass "Plugin loading order correct"
        fi
    elif [[ -n "$forge_plugin_line" ]] && [[ -z "$plugins_line" ]]; then
        # Forge plugin found but no plugins=() array - check for individual plugin sources
        local has_other_plugins=false
        if grep -q "source.*zsh-autosuggestions" "$zshrc_file" 2>/dev/null || \
           grep -q "source.*zsh-syntax-highlighting" "$zshrc_file" 2>/dev/null; then
            has_other_plugins=true
        fi
        
        if [[ "$has_other_plugins" == "true" ]]; then
            print_result warn "Manual plugin loading detected"
            print_result info "Ensure forge plugin is sourced AFTER zsh-autosuggestions and zsh-syntax-highlighting"
        fi
    fi
fi

# 4. Check ZSH theme RPROMPT
print_section "FORGE RIGHT PROMPT"

# Check if forge theme is loaded by checking environment variable
if [[ -n "$_FORGE_THEME_LOADED" ]]; then
    print_result pass "Forge theme loaded"
elif (( $+functions[p10k] )); then
    print_result info "Powerlevel10k detected (not using Forge theme)"
elif [[ -n "$ZSH_THEME" ]]; then
    print_result warn "Using theme: ${ZSH_THEME}"
    print_result instruction "To use Forge theme, add to ~/.zshrc:"
    print_result code "eval \"\$(forge zsh theme)\""
else
    print_result warn "No theme loaded"
    print_result instruction "To use Forge theme, add to ~/.zshrc:"
    print_result code "eval \"\$(forge zsh theme)\""
fi

# Helper function to compare versions
# Returns 0 if version1 >= version2, 1 otherwise
function version_gte() {
    local version1=$1
    local version2=$2
    
    # Remove 'v' prefix if present
    version1=${version1#v}
    version2=${version2#v}
    
    # Split versions into arrays
    local -a ver1_parts=(${(s:.:)version1})
    local -a ver2_parts=(${(s:.:)version2})
    
    # Compare each part
    for i in {1..3}; do
        local v1=${ver1_parts[$i]:-0}
        local v2=${ver2_parts[$i]:-0}
        
        # Remove any non-numeric suffix (e.g., "0-rc1" -> "0")
        v1=${v1%%[^0-9]*}
        v2=${v2%%[^0-9]*}
        
        if [[ $v1 -gt $v2 ]]; then
            return 0
        elif [[ $v1 -lt $v2 ]]; then
            return 1
        fi
    done
    
    return 0  # versions are equal
}

# 5. Check dependencies
print_section "Dependencies"

# Forge uses its built-in nucleo-picker for interactive selection
# No external fuzzy finder (like fzf) is required
print_result pass "Interactive picker: built-in (nucleo-picker)"

# Check for fd/fdfind - used for file discovery
if command -v fd &> /dev/null; then
    local fd_version=$(fd --version 2>&1 | awk '{print $2}')
    if [[ -n "$fd_version" ]]; then
        if version_gte "$fd_version" "10.0.0"; then
            print_result pass "fd: ${fd_version}"
        else
            print_result fail "fd: ${fd_version}" "Version 10.0.0 or higher required. Update: https://github.com/sharkdp/fd#installation"
        fi
    else
        print_result pass "fd: installed"
    fi
elif command -v fdfind &> /dev/null; then
    local fd_version=$(fdfind --version 2>&1 | awk '{print $2}')
    if [[ -n "$fd_version" ]]; then
        if version_gte "$fd_version" "10.0.0"; then
            print_result pass "fdfind: ${fd_version}"
        else
            print_result fail "fdfind: ${fd_version}" "Version 10.0.0 or higher required. Update: https://github.com/sharkdp/fd#installation"
        fi
    else
        print_result pass "fdfind: installed"
    fi
else
    print_result warn "fd/fdfind not found" "Enhanced file discovery. See installation: https://github.com/sharkdp/fd#installation"
fi

# Check for bat - used for syntax highlighting
if command -v bat &> /dev/null; then
    local bat_version=$(bat --version 2>&1 | awk '{print $2}')
    if [[ -n "$bat_version" ]]; then
        if version_gte "$bat_version" "0.20.0"; then
            print_result pass "bat: ${bat_version}"
        else
            print_result fail "bat: ${bat_version}" "Version 0.20.0 or higher required. Update: https://github.com/sharkdp/bat#installation"
        fi
    else
        print_result pass "bat: installed"
    fi
else
    print_result warn "bat not found" "Enhanced preview. See installation: https://github.com/sharkdp/bat#installation"
fi

# 6. Check required ZSH plugins
print_section "Required Plugins"

# Check for zsh-autosuggestions
if [[ " ${plugins[*]} " =~ " zsh-autosuggestions " ]] || \
   [[ -n "$fpath[(r)*zsh-autosuggestions*]" ]] || \
   (( $+functions[_zsh_autosuggest_accept] )); then
    print_result pass "zsh-autosuggestions loaded"
else
    print_result warn "zsh-autosuggestions not found"
    print_result info "Install plugin and add to plugins=() in .zshrc"
    print_result info "Installation guide: https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md"
fi

# Check for zsh-syntax-highlighting
if [[ " ${plugins[*]} " =~ " zsh-syntax-highlighting " ]] || \
   [[ -n "$fpath[(r)*zsh-syntax-highlighting*]" ]] || \
   (( $+functions[_zsh_highlight] )); then
    print_result pass "zsh-syntax-highlighting loaded"
else
    print_result warn "zsh-syntax-highlighting not found"
    print_result info "Install plugin and add to plugins=() in .zshrc"
    print_result info "Installation guide: https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md"
fi

# 7. Check system configuration
print_section "System"

# Check editor configuration (FORGE_EDITOR takes precedence over EDITOR)
if [[ -n "$FORGE_EDITOR" ]]; then
    print_result pass "FORGE_EDITOR: ${FORGE_EDITOR}"
    if [[ -n "$EDITOR" ]]; then
        print_result info "EDITOR also set: ${EDITOR} (ignored)"
    fi
elif [[ -n "$EDITOR" ]]; then
    print_result pass "EDITOR: ${EDITOR}"
    print_result info "TIP: Set FORGE_EDITOR for forge-specific editor"
else
    print_result warn "No editor configured" "export EDITOR=vim or export FORGE_EDITOR=vim"
fi

# Check PATH for common issues
if [[ "$PATH" == *"/usr/local/bin"* ]] || [[ "$PATH" == *"/usr/bin"* ]]; then
    print_result pass "PATH: configured"
else
    print_result warn "PATH may need common directories" "Ensure /usr/local/bin or /usr/bin is in PATH"
fi

# 7. Check keyboard configuration (Alt/Option key as Meta)
print_section "Keyboard Configuration"

local platform=$(uname)
local meta_key_ok=false
local check_performed=false

if [[ "$platform" == "Darwin" ]]; then
    # macOS checks
    if [[ "$TERM_PROGRAM" == "vscode" ]]; then
        check_performed=true
        # Check VS Code settings
        local vscode_settings="${HOME}/Library/Application Support/Code/User/settings.json"
        if [[ -f "$vscode_settings" ]]; then
            if grep -q '"terminal.integrated.macOptionIsMeta"[[:space:]]*:[[:space:]]*true' "$vscode_settings" 2>/dev/null; then
                print_result pass "VS Code: Option key configured as Meta"
                meta_key_ok=true
            else
                print_result warn "VS Code: Option key NOT configured as Meta"
                print_result instruction "Option+F and Option+B shortcuts won't work for word navigation"
                print_result instruction "Add to VS Code settings.json:"
                print_result code '"terminal.integrated.macOptionIsMeta": true'
                print_result instruction "Then reload VS Code: Cmd+Shift+P β†’ Reload Window"
            fi
        else
            print_result warn "VS Code settings file not found"
            print_result info "Expected: ${vscode_settings}"
        fi
    elif [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
        check_performed=true
        # Check iTerm2 preferences
        local iterm_prefs="${HOME}/Library/Preferences/com.googlecode.iterm2.plist"
        if [[ -f "$iterm_prefs" ]]; then
            # Check if either Left or Right Option key is set to Esc+ (value 2)
            local option_setting=$(defaults read com.googlecode.iterm2 2>/dev/null | grep -E '"(Left |Right )?Option Key Sends"' | grep -o '[0-9]' | head -1)
            if [[ "$option_setting" == "2" ]]; then
                print_result pass "iTerm2: Option key configured as Esc+"
                meta_key_ok=true
            else
                print_result warn "iTerm2: Option key NOT configured as Esc+"
                print_result instruction "Option+F and Option+B shortcuts won't work for word navigation"
                print_result instruction "Configure in iTerm2:"
                print_result info "Preferences β†’ Profiles β†’ Keys β†’ Left/Right Option Key β†’ Esc+"
            fi
        else
            print_result warn "iTerm2 preferences not found"
            print_result info "Expected: ${iterm_prefs}"
        fi
    elif [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
        check_performed=true
        # Check Terminal.app preferences
        local terminal_prefs="${HOME}/Library/Preferences/com.apple.Terminal.plist"
        if [[ -f "$terminal_prefs" ]]; then
            local use_option=$(defaults read com.apple.Terminal 2>/dev/null | grep -E 'useOptionAsMetaKey' | grep -o '[0-9]' | head -1)
            if [[ "$use_option" == "1" ]]; then
                print_result pass "Terminal.app: Option key configured as Meta"
                meta_key_ok=true
            else
                print_result warn "Terminal.app: Option key NOT configured as Meta"
                print_result instruction "Option+F and Option+B shortcuts won't work for word navigation"
                print_result instruction "Configure in Terminal.app:"
                print_result info "Preferences β†’ Profiles β†’ Keyboard β†’ βœ“ Use Option as Meta key"
            fi
        else
            print_result warn "Terminal.app preferences not found"
            print_result info "Expected: ${terminal_prefs}"
        fi
    fi
    
    # If no specific terminal detected, provide general guidance for macOS
    if [[ "$check_performed" == "false" ]]; then
        print_result info "Terminal: ${TERM_PROGRAM:-unknown}"
        print_result info "For Option key shortcuts (word navigation) to work:"
        print_result info "β€’ VS Code: Settings β†’ terminal.integrated.macOptionIsMeta β†’ true"
        print_result info "β€’ iTerm2: Preferences β†’ Profiles β†’ Keys β†’ Option Key β†’ Esc+"
        print_result info "β€’ Terminal.app: Preferences β†’ Profiles β†’ Keyboard β†’ Use Option as Meta"
        print_result info "Run 'forge zsh keyboard' for detailed keyboard shortcuts"
    fi
    
elif [[ "$platform" == "Linux" ]]; then
    # Linux checks
    if [[ "$TERM_PROGRAM" == "vscode" ]]; then
        check_performed=true
        # Check VS Code settings on Linux
        local vscode_settings="${HOME}/.config/Code/User/settings.json"
        if [[ -f "$vscode_settings" ]]; then
            # On Linux, check for sendAltAsMetaKey (deprecated but still works) or macOptionIsMeta
            if grep -q '"terminal.integrated.sendAltAsMetaKey"[[:space:]]*:[[:space:]]*true' "$vscode_settings" 2>/dev/null || \
               grep -q '"terminal.integrated.macOptionIsMeta"[[:space:]]*:[[:space:]]*true' "$vscode_settings" 2>/dev/null; then
                print_result pass "VS Code: Alt key configured as Meta"
                meta_key_ok=true
            else
                print_result warn "VS Code: Alt key NOT configured as Meta"
                print_result instruction "Alt+F and Alt+B shortcuts won't work for word navigation"
                print_result instruction "Add to VS Code settings.json:"
                print_result code '"terminal.integrated.sendAltAsMetaKey": true'
                print_result instruction "Then reload VS Code: Ctrl+Shift+P β†’ Reload Window"
            fi
        else
            print_result warn "VS Code settings file not found"
            print_result info "Expected: ${vscode_settings}"
        fi
    elif [[ -n "$GNOME_TERMINAL_SERVICE" ]] || [[ "$COLORTERM" == "gnome-terminal" ]]; then
        check_performed=true
        # GNOME Terminal check
        local profile_id=$(gsettings get org.gnome.Terminal.ProfilesList default 2>/dev/null | tr -d "'")
        if [[ -n "$profile_id" ]]; then
            local alt_sends_escape=$(gsettings get org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:${profile_id}/ use-theme-colors 2>/dev/null)
            # GNOME Terminal doesn't have a simple setting check - most distributions enable Alt by default
            print_result pass "GNOME Terminal: Alt key typically works by default"
            print_result info "If Alt+F/B don't work, check: Preferences β†’ Profile β†’ Keyboard"
            meta_key_ok=true
        else
            print_result info "GNOME Terminal detected"
            print_result info "Alt key typically works by default for word navigation"
        fi
    elif [[ "$COLORTERM" == "truecolor" ]] && command -v konsole &> /dev/null; then
        check_performed=true
        # Konsole (KDE) - Alt typically works by default
        print_result pass "Konsole: Alt key typically works by default"
        print_result info "If Alt+F/B don't work, check: Settings β†’ Edit Profile β†’ Keyboard"
        meta_key_ok=true
    elif [[ -n "$ALACRITTY_SOCKET" ]] || [[ "$TERM" == "alacritty" ]]; then
        check_performed=true
        # Alacritty check - look for config file
        local alacritty_config="${HOME}/.config/alacritty/alacritty.yml"
        local alacritty_config_toml="${HOME}/.config/alacritty/alacritty.toml"
        
        if [[ -f "$alacritty_config" ]] || [[ -f "$alacritty_config_toml" ]]; then
            print_result pass "Alacritty: Alt key typically works by default"
            print_result info "If Alt+F/B don't work, ensure no conflicting key bindings"
            meta_key_ok=true
        else
            print_result pass "Alacritty: Alt key typically works by default"
            print_result info "Config: ${alacritty_config} or ${alacritty_config_toml}"
        fi
    elif [[ "$TERM" == "xterm" ]] || [[ "$TERM" == "xterm-256color" ]]; then
        check_performed=true
        # xterm - check .Xresources
        local xresources="${HOME}/.Xresources"
        if [[ -f "$xresources" ]]; then
            if grep -q "XTerm\*metaSendsEscape:[[:space:]]*true" "$xresources" 2>/dev/null || \
               grep -q "XTerm\*eightBitInput:[[:space:]]*false" "$xresources" 2>/dev/null; then
                print_result pass "xterm: Meta key configured"
                meta_key_ok=true
            else
                print_result warn "xterm: Meta key may not be configured"
                print_result instruction "Add to ~/.Xresources:"
                print_result code "XTerm*metaSendsEscape: true"
                print_result instruction "Then reload: xrdb ~/.Xresources"
            fi
        else
            print_result info "xterm detected"
            print_result info "To enable Alt as Meta, add to ~/.Xresources:"
            print_result info "XTerm*metaSendsEscape: true"
        fi
    fi
    
    # If no specific terminal detected, provide general guidance for Linux
    if [[ "$check_performed" == "false" ]]; then
        print_result info "Terminal: ${TERM_PROGRAM:-$TERM}"
        print_result info "For Alt key shortcuts (word navigation) to work:"
        print_result info "β€’ VS Code: Settings β†’ terminal.integrated.sendAltAsMetaKey β†’ true"
        print_result info "β€’ GNOME Terminal: Usually works by default"
        print_result info "β€’ Konsole: Usually works by default"
        print_result info "β€’ xterm: Add 'XTerm*metaSendsEscape: true' to ~/.Xresources"
        print_result info "Run 'forge zsh keyboard' for detailed keyboard shortcuts"
    fi
else
    # Other platforms (BSD, etc.)
    print_result info "Keyboard check: Platform ${platform} - manual verification needed"
    print_result info "Ensure Alt/Meta key is configured for word navigation shortcuts"
fi

# 8. Check font and Nerd Font support
print_section "Nerd Font"

# Check if Nerd Font is enabled via environment variables
if [[ -n "$NERD_FONT" ]]; then
    if [[ "$NERD_FONT" == "1" || "$NERD_FONT" == "true" ]]; then
        print_result pass "NERD_FONT: enabled"
    else
        print_result warn "NERD_FONT: disabled (${NERD_FONT})"
        print_result instruction "Enable Nerd Font by setting:"
        print_result code "export NERD_FONT=1"
    fi
elif [[ -n "$USE_NERD_FONT" ]]; then
    if [[ "$USE_NERD_FONT" == "1" || "$USE_NERD_FONT" == "true" ]]; then
        print_result pass "USE_NERD_FONT: enabled"
    else
        print_result warn "USE_NERD_FONT: disabled (${USE_NERD_FONT})"
        print_result instruction "Enable Nerd Font by setting:"
        print_result code "export NERD_FONT=1"
    fi
else
    print_result pass "Nerd Font: enabled (default)"
    print_result info "Forge will auto-detect based on terminal capabilities"
fi

# Show actual icons used in Forge theme for manual verification (skip if explicitly disabled)
local nerd_font_disabled=false
if [[ -n "$NERD_FONT" && "$NERD_FONT" != "1" && "$NERD_FONT" != "true" ]]; then
    nerd_font_disabled=true
elif [[ -n "$USE_NERD_FONT" && "$USE_NERD_FONT" != "1" && "$USE_NERD_FONT" != "true" ]]; then
    nerd_font_disabled=true
fi

if [[ "$nerd_font_disabled" == "false" ]]; then
    echo ""
    echo "$(yellow "Visual Check [Manual Verification Required]")"
echo "   $(bold "σ±™Ί FORGE 33.0k") $(cyan "ξ°™ tonic-1.0")"
    echo ""
    echo "   Forge uses Nerd Fonts to enrich cli experience, can you see all the icons clearly without any overlap?"
    echo "   If you see boxes (β–‘) or question marks (?), install a Nerd Font from:"
    echo "   $(dim "https://www.nerdfonts.com/")"
    echo ""
fi

# Summary
echo ""

if [[ $failed -eq 0 && $warnings -eq 0 ]]; then
    echo "$(green "${PASS}") $(bold "All checks passed") $(dim "(${passed})")"
    exit 0
elif [[ $failed -eq 0 ]]; then
    echo "$(yellow "${WARN}") $(bold "${warnings} warnings") $(dim "(${passed} passed)")"
    exit 0
else
    echo "$(red "${FAIL}") $(bold "${failed} failed") $(dim "(${warnings} warnings, ${passed} passed)")"
    exit 1
fi