Back to Skills

completions

majiayu000
Updated Today
2 views
58
9
58
View on GitHub
Otherautomation

About

This skill helps developers write and manage custom ZSH completion files using the repository's conventions. It provides guidance for implementing completions for CLI tools, fixing existing files, and understanding the loading process. Use it when working with zsh autocomplete, but not for homebrew package installations which handle completions automatically.

Quick Install

Claude Code

Recommended
Plugin CommandRecommended
/plugin add https://github.com/majiayu000/claude-skill-registry
Git CloneAlternative
git clone https://github.com/majiayu000/claude-skill-registry.git ~/.claude/skills/completions

Copy and paste this command in Claude Code to install this skill

Documentation

Completions

Guide for writing and managing custom ZSH completion files in this dotfiles repository.

When to Use

  • Implementing custom completions for CLI tools
  • Fixing or updating existing completion files
  • Understanding how completions are loaded in this repo

Do NOT use when installing homebrew packages - they handle completions automatically.

Repository Conventions

File Naming

Completion files in this repo use: <topic>/completion.zsh

Example: claude/completion.zsh

Loading Process

From zsh/zshrc.symlink:

  1. compinit is called to initialize the completion system
  2. All */completion.zsh files are sourced
  3. Files are sourced directly, NOT added to fpath

File Structure

#!/usr/bin/env zsh

# Define completion function
_toolname() {
  local line state

  # Define options
  local -a options=(
    '-h[Display help]'
    '--help[Display help]'
  )

  # Define subcommands
  local -a subcommands=(
    'command:Description'
  )

  _arguments -C \
    "${options[@]}" \
    '1: :->command' \
    '*::arg:->args'

  case $state in
    command)
      _describe -t commands 'tool command' subcommands
      ;;
    args)
      # Handle subcommand args
      ;;
  esac
}

# Register completion
compdef _toolname toolname

Key Patterns

Registration

Use compdef at the end of the file:

compdef _toolname toolname

NOT the #compdef directive (that's for files in fpath).

Options Format

local -a options=(
  '-h[Display help]'
  '--help[Display help]'
  '--flag[Description]'
  '--option[Description]:value:'
  '--file[Description]:file:_files'
  '--dir[Description]:directory:_directories'
)

Subcommands

local -a subcommands=(
  'command:Description'
  'subcommand:What it does'
)

_describe -t commands 'tool command' subcommands

Argument Handling

_arguments -C \
  "${options[@]}" \
  '1: :->command' \
  '*::arg:->args'

case $state in
  command)
    _describe -t commands 'tool command' subcommands
    ;;
  args)
    case ${line[1]} in
      subcommand)
        _arguments \
          '--subcommand-option[Description]' \
          '1:arg:'
        ;;
    esac
    ;;
esac

Nested Subcommands

For tools like git or docker with deep command hierarchies:

_tool_subcommand() {
  local line state

  local -a sub_subcommands=(
    'action:Description'
  )

  _arguments -C \
    '1: :->command' \
    '*::arg:->args'

  case $state in
    command)
      _describe -t commands 'tool subcommand command' sub_subcommands
      ;;
  esac
}

Common Completers

Built-in zsh completion functions:

  • _files - File paths
  • _directories - Directory paths
  • _values - Predefined values
  • _describe - Command descriptions
  • _arguments - Argument parsing

File Completion

'--config[Config file]:file:_files'

Choice Completion

'--format[Output format]:format:(json yaml text)'

Multiple Values

'--env[Environment variables]:env:'  # Free form
'--scope[Scope]:scope:(local user project)'  # Fixed choices

Testing

After creating/modifying a completion file:

  1. Reload shell: source ~/.zshrc
  2. Test completion: tool <TAB>
  3. Test subcommands: tool subcommand <TAB>
  4. Test options: tool --<TAB>

Generating Completions

Steps to create completions for a new tool:

  1. Run tool --help to see main options
  2. Run tool subcommand --help for each subcommand
  3. Create <topic>/completion.zsh
  4. Define _toolname() function with all discovered options
  5. Register with compdef _toolname toolname
  6. Test thoroughly

Common Issues

"command not found: _arguments"

The completion function is being executed instead of sourced. Ensure:

  • File is named completion.zsh (not completions.zsh)
  • Using compdef (not #compdef)
  • File is in a topic directory that gets sourced

"can only be called from completion function"

Using #compdef directive when file is sourced directly. Use compdef registration instead.

Completions Not Loading

  1. Check file naming: */completion.zsh
  2. Verify file is being sourced: echo $ZSH/**/*.zsh | grep completion
  3. Check for syntax errors: zsh -n path/to/completion.zsh

Examples

See existing completion files:

  • claude/completion.zsh - Complex multi-level subcommands
  • gcloud/completions.zsh - Third-party completion sourcing

GitHub Repository

majiayu000/claude-skill-registry
Path: skills/completions

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill

Algorithmic Art Generation

Meta

This skill helps developers create algorithmic art using p5.js, focusing on generative art, computational aesthetics, and interactive visualizations. It automatically activates for topics like "generative art" or "p5.js visualization" and guides you through creating unique algorithms with features like seeded randomness, flow fields, and particle systems. Use it when you need to build reproducible, code-driven artistic patterns.

View skill

cloudflare-turnstile

Meta

This skill provides comprehensive guidance for implementing Cloudflare Turnstile as a CAPTCHA-alternative bot protection system. It covers integration for forms, login pages, API endpoints, and frameworks like React/Next.js/Hono, while handling invisible challenges that maintain user experience. Use it when migrating from reCAPTCHA, debugging error codes, or implementing token validation and E2E tests.

View skill