Skip to content

refactor: fix double-loading and sequencing issues in zsh completion setup #426

@paolomainardi

Description

@paolomainardi

🤖 This was written by an AI agent on behalf of @paolomainardi.

Problem

The shell completion loading in sparkdock.zshrc and completions.zsh has overlapping responsibilities that cause double-loading and confused semantics on every shell startup.

1. Double-loading

sparkdock.zshrc runs an autoload + compdef loop over ~/.local/share/zsh/site-functions/_* (line 31-34), then sources completions.zsh which unconditionally sources the same files (lines 21-23, 32-34). Pre-existing completion files get registered twice — once via autoload, once via source.

2. Confused autoload vs source semantics

autoload -Uz _opencode tells zsh to load lazily on first use. Then source "${_opencode_completion_file}" immediately loads it eagerly, overriding the autoload stub. These are contradictory strategies applied to the same file.

3. Sequencing issue

The autoload loop runs before completions.zsh, so freshly generated completion files (the fallback path) aren't picked up by autoload until the next shell session. The source call is a workaround for this ordering problem.

4. Duplicate command_exists function

Defined in both init.zsh:6-8 and completions.zsh:9-11.

Proposed fix

Reorder sparkdock.zshrc so completions.zsh runs before the autoload loop:

source init.zsh           # fpath setup, oh-my-zsh
ensure compinit           # fallback
source completions.zsh    # generate missing files only (drop source calls)
source aliases.zsh
autoload+compdef loop     # register everything in site-functions

This eliminates double-loading, fixes the sequencing, and unifies on a single loading strategy (autoload).

Additionally:

  • Remove source calls from completions.zsh — it should only generate missing files
  • Remove duplicate command_exists from completions.zsh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions