Skip to content

Zsh completions: zstyle not registered for git subcommand #83

@filipegiusti

Description

@filipegiusti

Problem

Zsh completions for git gtr don't work out of the box following the README instructions.

The _git-gtr completion file contains a zstyle line to register gtr as a git subcommand:

zstyle ':completion:*:*:git:*' user-commands gtr:'Git worktree management'

However, this line only executes when the completion function is autoloaded — which happens after zsh tries to complete git gtr. Git's completion system needs to know about gtr as a valid subcommand before triggering completion, creating a chicken-and-egg problem.

Steps to Reproduce

  1. Follow README instructions for Zsh:
    mkdir -p ~/.zsh/completions
    cp completions/_git-gtr ~/.zsh/completions/
    # Add to ~/.zshrc: fpath=(~/.zsh/completions $fpath)
  2. Reload shell: source ~/.zshrc
  3. Try git gtr <TAB>
  4. No completions appear

Workaround

Add the zstyle line directly to ~/.zshrc:

zstyle ':completion:*:*:git:*' user-commands gtr:'Git worktree management'

Possible Solutions

  1. Update README — document that users must add the zstyle line to their .zshrc
  2. Create init snippet — separate file users source at shell init (not autoloaded)
  3. Oh My Zsh plugin — create a proper plugin structure that handles init
  4. Different registration approach — investigate if there's a way to register git subcommands that works with autoload

Looking for guidance on preferred approach before submitting a PR.

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