completions

Implement and manage ZSH completion files for CLI tools in dotfiles repositories.

7|Updated Aug 16, 2016
One-click install
npx skills add https://github.com/bendrucker/dotfiles --skill completions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: completions
Source: https://github.com/bendrucker/dotfiles/tree/main/.claude/skills/completions
Command: npx skills add https://github.com/bendrucker/dotfiles --skill completions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Manually configuring ZSH shell completions can be a complex and error-prone task, leading to inconsistent behavior or missing autocomplete features for your command-line tools. This Skill provides a standardized, guided approach to creating, managing, and troubleshooting custom ZSH completions, saving you development time and ensuring a smooth command-line experience.

Core Features & Use Cases

  • Standardized Completion Structure: Learn and apply consistent conventions for file naming (<topic>/completion.zsh) and loading, ensuring your custom completions integrate seamlessly with your dotfiles.
  • Detailed Syntax Guide: Access clear examples and explanations for registering completions (compdef), defining options (_arguments), handling subcommands (_describe), and utilizing common completers (_files, _directories).
  • Troubleshooting & Testing: Benefit from dedicated sections on common issues and a robust testing workflow to quickly validate your custom completions and resolve problems.
  • Use Case: You've developed a new CLI tool and want to provide a rich autocomplete experience for its commands, options, and arguments. This Skill guides you step-by-step through creating the completion.zsh file, defining its structure, and testing it to ensure users can effortlessly navigate your tool, boosting their productivity.

Quick Start

Example: Define and register a simple completion for 'mytool'

This snippet shows how to create a basic completion function

and link it to your command.

_mytool() { local -a options=( '-h[Display help]' '--version[Show version]' ) _arguments "${options[@]}" } compdef _mytool mytool

Frequently Asked Questions about completions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create ZSH completions for my CLI tool?

ZSH completions are custom functions that enable autocomplete for command-line tools. Create a `<topic>/completion.zsh` file defining completion logic with `_arguments` for options and `compdef` to register the function to your command. Load it via compinit in your dotfiles to activate autocomplete.

What's the correct file structure for ZSH completion files?

Follow the convention `<topic>/completion.zsh` within your dotfiles repository. Define a completion function prefixed with underscore (e.g., `_mytool`), use `_arguments` to specify options and arguments, then register it with `compdef _mytool mytool`. Ensure compinit loads your completion files.

How do I handle subcommands in ZSH completions?

Use `_describe` to list subcommands and their descriptions, nested within your main completion function. Define separate completion logic for each subcommand, then integrate them into the parent function's argument handling to provide context-aware autocomplete at each level.

Why aren't my ZSH completions loading?

Verify compinit is sourced in your shell configuration, completion files follow the `<topic>/completion.zsh` naming convention, and `compdef` registration matches your command name exactly. Common issues include missing compdef calls, incorrect file paths, or compinit running before completion files are sourced.

Can I test ZSH completions before deploying them?

Yes. Source your completion file directly in your shell session, then test autocomplete by typing your command and pressing Tab. Use dedicated testing workflows to validate option parsing, argument handling, and subcommand suggestions, catching errors early before adding to dotfiles.

What's the difference between _arguments, _files, and _describe in completions?

`_arguments` defines command options and arguments with descriptions; `_files` and `_directories` are built-in completers that suggest filesystem paths. Combine them within `_arguments` specs to provide context-specific suggestions: flags get option descriptions, file arguments suggest paths.