Skip to main content
The moon completions command generates shell completion scripts for the moon CLI, enabling tab-completion of commands, subcommands, and options in your preferred shell.
moon completions [options]

Options

--shell

Supported shells:
  • bash - Bash shell
  • zsh - Zsh shell
  • fish - Fish shell
  • pwsh - PowerShell
  • elvish - Elvish shell
  • nu - Nushell

How it works

  1. The command detects your current shell or uses the --shell option
  2. Generates the appropriate completion script for that shell
  3. Outputs the script to stdout (quiet mode)
  4. You can redirect this output to your shell’s completion directory
The completions enable:
  • Tab-completion for all moon commands
  • Tab-completion for command options and flags
  • Contextual suggestions based on your current command

Examples

Auto-detect and install completions

Bash

# Generate and save to completions directory
moon completions --shell bash > ~/.local/share/bash-completion/completions/moon

# Or for system-wide installation
sudo moon completions --shell bash > /usr/share/bash-completion/completions/moon

Zsh

# Generate and save to completions directory
moon completions --shell zsh > ~/.zsh/completions/_moon

# Make sure fpath includes the directory
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc

Fish

# Generate and save to completions directory
moon completions --shell fish > ~/.config/fish/completions/moon.fish

PowerShell

# Generate and save to profile
moon completions --shell pwsh >> $PROFILE

Nushell

# Generate and save to config
moon completions --shell nu > ~/.config/nushell/completions/moon.nu

# Add to your config.nu:
echo 'source ~/.config/nushell/completions/moon.nu' >> ~/.config/nushell/config.nu

Auto-detect current shell

# Let moon detect your shell automatically
moon completions

Test completions without installing

# View the generated script
moon completions --shell bash | less

Unsupported shells

If you use a shell that doesn’t support completions, the command will output an error message:
<shell-name> does not currently support completions
And return exit code 1.

Exit codes

  • 0 - Completions generated successfully
  • 1 - Shell doesn’t support completions or generation failed

Build docs developers (and LLMs) love