Skip to content

Z_A_USECOMP: recache subcommand not completing via shim mechanism #5

Description

@HaleTom

Summary

The Z_A_USECOMP=1 shim mechanism doesn't add recache to _zinit's tab-completable subcommands. The _zinit_shim approach of chaining _zinit_recache and _zinit has a fundamental issue: _zinit_recache uses _arguments which creates a nested _arguments context when called directly from the shim (bypassing _call_function).

Root cause

_zinit's completion defines subcommands in __zinit_commands() (a hardcoded list in the _zinit file). The recache subcommand is not in this list. The shim tries to work around this by calling both _zinit_recache and _zinit, but:

  1. _zinit_recache's _arguments -C call, when invoked directly from the shim (not via _call_function), may conflict with the outer completion context.
  2. _zinit still doesn't list recache in its subcommands, so the base completion never offers it.

Steps to reproduce

  1. Load z-a-eval with Z_A_USECOMP=1:
    zinit atinit'Z_A_USECOMP=1' light-mode for NICHOLAS85/z-a-eval
  2. Type zinit rec and press Tab
  3. No completion for recache is offered

Expected behavior

zinit rec<TAB> should complete to zinit recache.

Suggested fix

Instead of (or in addition to) the shim mechanism, patch _zinit's __zinit_commands to include the recache subcommand. This can be done by sourcing the _zinit file (minus the final _zinit "$@" call) and injecting recache into the commands array:

# Source _zinit to define all functions (makes _zinit a real function, not autoload stub)
eval "$(head -n -1 "${ZINIT[BIN_DIR]}/_zinit")" 2>/dev/null
# Inject recache into __zinit_commands
eval "$(sed -n '/^__zinit_commands()/,/^} # \]\]\]$/p' "${ZINIT[BIN_DIR]}/_zinit" \
  | sed "/recently:Show plugins that changed recently/a\\    'recache:Regenerate eval cache (z-a-eval annex)'")"

Since _zinit becomes a real function (not an autoload stub), the autoload mechanism won't overwrite the patched __zinit_commands on first tab completion.

Environment

  • Zsh 5.9+
  • zinit (zdharma-continuum) latest
  • z-a-eval main branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions