Shell Completion
Shell completion provides tab-completion for commands, subcommands, options, and even domain names from your configuration.
Supported Shells
Section titled “Supported Shells”- Bash - Most common on Linux
- Zsh - Default on macOS
- Fish - Modern shell with great defaults
Quick Setup
Section titled “Quick Setup”Add to ~/.bashrc:
eval "$(nextdns-blocker completion bash)"Then reload:
source ~/.bashrcAdd to ~/.zshrc:
eval "$(nextdns-blocker completion zsh)"Then reload:
source ~/.zshrcSave to completions directory:
nextdns-blocker completion fish > ~/.config/fish/completions/nextdns-blocker.fishFish loads completions automatically.
What Completes
Section titled “What Completes”Commands
Section titled “Commands”nextdns-blocker <TAB># Shows: status, unblock, config, watchdog, panic, pending, allow, disallow, update, completionSubcommands
Section titled “Subcommands”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, cancelOptions
Section titled “Options”nextdns-blocker config push --<TAB># Shows: --dry-run, --verbose, --help
nextdns-blocker --<TAB># Shows: --help, --version, --no-colorDomain Names
Section titled “Domain Names”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...Pending Action IDs
Section titled “Pending Action IDs”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 IDsAdvanced Setup
Section titled “Advanced Setup”Bash (Alternative)
Section titled “Bash (Alternative)”If eval is slow, save to a file:
# Generate oncenextdns-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-blockerZsh (Alternative)
Section titled “Zsh (Alternative)”For Oh-My-Zsh users:
# Save to Oh-My-Zsh completionsnextdns-blocker completion zsh > ~/.oh-my-zsh/completions/_nextdns-blocker
# Rebuild cacherm ~/.zcompdump*compinitZsh (fpath method)
Section titled “Zsh (fpath method)”# Create completions directorymkdir -p ~/.zfunc
# Generate completionnextdns-blocker completion zsh > ~/.zfunc/_nextdns-blocker
# Add to .zshrc (before compinit)fpath=(~/.zfunc $fpath)autoload -Uz compinit && compinitVerifying Setup
Section titled “Verifying Setup”Test Completion
Section titled “Test Completion”After setup, test in a new terminal:
nextdns-blocker <TAB><TAB>Should show available commands.
Check Script Generated
Section titled “Check Script Generated”nextdns-blocker completion bash | head -20Should output shell completion script.
Dynamic Completions
Section titled “Dynamic Completions”Domain names and pending IDs are read dynamically from your configuration:
- Completion script runs
- Reads
config.jsonfor domains - Reads
pending.jsonfor action IDs - Returns matches to shell
This means:
- Add a domain to config → immediately available for completion
- Create pending action → ID immediately completable
Updating Completions
Section titled “Updating Completions”After updating NextDNS Blocker, regenerate completions:
# Basheval "$(nextdns-blocker completion bash)"
# Zsheval "$(nextdns-blocker completion zsh)"
# Fishnextdns-blocker completion fish > ~/.config/fish/completions/nextdns-blocker.fishOr restart your terminal.
Troubleshooting
Section titled “Troubleshooting”Completion not working
Section titled “Completion not working”-
Check shell type:
Terminal window echo $SHELL -
Verify completion installed:
Terminal window # Bashcomplete -p nextdns-blocker# Zshwhich _nextdns-blocker -
Regenerate:
Terminal window eval "$(nextdns-blocker completion bash)" # or zsh
Domain names not completing
Section titled “Domain names not completing”-
Check config exists:
Terminal window nextdns-blocker config show -
Verify domains in blocklist:
Terminal window cat ~/.config/nextdns-blocker/config.json | grep domain
Slow completion
Section titled “Slow completion”If completion is slow:
- Check config file size - Very large configs might be slow
- Use file-based completion instead of
eval - Check disk speed - Config is read on each completion
Pending IDs not completing
Section titled “Pending IDs not completing”-
Check pending actions exist:
Terminal window nextdns-blocker pending list -
Verify pending.json readable:
Terminal window cat ~/.local/share/nextdns-blocker/pending.json
Shell-Specific Notes
Section titled “Shell-Specific Notes”- Requires
bash-completionpackage on some systems - Minimum Bash 4.0 recommended
- Works with Oh-My-Zsh, Prezto, etc.
- May need
compinitcall after adding completions
- Most straightforward setup
- Completions auto-load from
~/.config/fish/completions/ - No shell restart needed
Uninstalling Completions
Section titled “Uninstalling Completions”Remove from ~/.bashrc:
# Remove this line:eval "$(nextdns-blocker completion bash)"Or delete file:
rm ~/.local/share/bash-completion/completions/nextdns-blockerRemove from ~/.zshrc:
# Remove this line:eval "$(nextdns-blocker completion zsh)"Delete completion file:
rm ~/.config/fish/completions/nextdns-blocker.fish