Skip to content

Shell Completion

Shell completion provides tab-completion for commands, subcommands, options, and even domain names from your configuration.

  • Bash - Most common on Linux
  • Zsh - Default on macOS
  • Fish - Modern shell with great defaults

Add to ~/.bashrc:

Terminal window
eval "$(nextdns-blocker completion bash)"

Then reload:

Terminal window
source ~/.bashrc

Add to ~/.zshrc:

Terminal window
eval "$(nextdns-blocker completion zsh)"

Then reload:

Terminal window
source ~/.zshrc

Save to completions directory:

Terminal window
nextdns-blocker completion fish > ~/.config/fish/completions/nextdns-blocker.fish

Fish loads completions automatically.

Terminal window
nextdns-blocker <TAB>
# Shows: status, unblock, config, watchdog, panic, pending, allow, disallow, update, completion
Terminal window
nextdns-blocker config <TAB>
# Shows: show, edit, validate, set, push
nextdns-blocker watchdog <TAB>
# Shows: status, install, uninstall, enable, disable
nextdns-blocker pending <TAB>
# Shows: list, show, cancel
Terminal window
nextdns-blocker config push --<TAB>
# Shows: --dry-run, --verbose, --help
nextdns-blocker --<TAB>
# Shows: --help, --version, --no-color
Terminal window
nextdns-blocker unblock <TAB>
# Shows domains from your blocklist:
# reddit.com, twitter.com, youtube.com...
nextdns-blocker disallow <TAB>
# Shows domains from your allowlist:
# aws.amazon.com, github.com...
Terminal window
nextdns-blocker pending cancel <TAB>
# Shows pending action IDs:
# pnd_20240115_143000_a1b2c3, pnd_20240115_150000_d4e5f6...
nextdns-blocker pending show <TAB>
# Same - shows pending action IDs

If eval is slow, save to a file:

Terminal window
# Generate once
nextdns-blocker completion bash > ~/.local/share/bash-completion/completions/nextdns-blocker
# Or system-wide (requires sudo)
nextdns-blocker completion bash | sudo tee /etc/bash_completion.d/nextdns-blocker

For Oh-My-Zsh users:

Terminal window
# Save to Oh-My-Zsh completions
nextdns-blocker completion zsh > ~/.oh-my-zsh/completions/_nextdns-blocker
# Rebuild cache
rm ~/.zcompdump*
compinit
Terminal window
# Create completions directory
mkdir -p ~/.zfunc
# Generate completion
nextdns-blocker completion zsh > ~/.zfunc/_nextdns-blocker
# Add to .zshrc (before compinit)
fpath=(~/.zfunc $fpath)
autoload -Uz compinit && compinit

After setup, test in a new terminal:

Terminal window
nextdns-blocker <TAB><TAB>

Should show available commands.

Terminal window
nextdns-blocker completion bash | head -20

Should output shell completion script.

Domain names and pending IDs are read dynamically from your configuration:

  1. Completion script runs
  2. Reads config.json for domains
  3. Reads pending.json for action IDs
  4. Returns matches to shell

This means:

  • Add a domain to config → immediately available for completion
  • Create pending action → ID immediately completable

After updating NextDNS Blocker, regenerate completions:

Terminal window
# Bash
eval "$(nextdns-blocker completion bash)"
# Zsh
eval "$(nextdns-blocker completion zsh)"
# Fish
nextdns-blocker completion fish > ~/.config/fish/completions/nextdns-blocker.fish

Or restart your terminal.

  1. Check shell type:

    Terminal window
    echo $SHELL
  2. Verify completion installed:

    Terminal window
    # Bash
    complete -p nextdns-blocker
    # Zsh
    which _nextdns-blocker
  3. Regenerate:

    Terminal window
    eval "$(nextdns-blocker completion bash)" # or zsh
  1. Check config exists:

    Terminal window
    nextdns-blocker config show
  2. Verify domains in blocklist:

    Terminal window
    cat ~/.config/nextdns-blocker/config.json | grep domain

If completion is slow:

  1. Check config file size - Very large configs might be slow
  2. Use file-based completion instead of eval
  3. Check disk speed - Config is read on each completion
  1. Check pending actions exist:

    Terminal window
    nextdns-blocker pending list
  2. Verify pending.json readable:

    Terminal window
    cat ~/.local/share/nextdns-blocker/pending.json
  • Requires bash-completion package on some systems
  • Minimum Bash 4.0 recommended
  • Works with Oh-My-Zsh, Prezto, etc.
  • May need compinit call after adding completions
  • Most straightforward setup
  • Completions auto-load from ~/.config/fish/completions/
  • No shell restart needed

Remove from ~/.bashrc:

Terminal window
# Remove this line:
eval "$(nextdns-blocker completion bash)"

Or delete file:

Terminal window
rm ~/.local/share/bash-completion/completions/nextdns-blocker

Remove from ~/.zshrc:

Terminal window
# Remove this line:
eval "$(nextdns-blocker completion zsh)"

Delete completion file:

Terminal window
rm ~/.config/fish/completions/nextdns-blocker.fish