Skip to content

ISC bind-utils dig completion with hints helper option file for "@"#1625

Open
mave007 wants to merge 3 commits intoscop:mainfrom
mave007:completion/dig
Open

ISC bind-utils dig completion with hints helper option file for "@"#1625
mave007 wants to merge 3 commits intoscop:mainfrom
mave007:completion/dig

Conversation

@mave007
Copy link
Copy Markdown

@mave007 mave007 commented Apr 30, 2026

Summary

Adding dedicated completion for ISC BIND dig (completions-core/dig.bash), registers it in the build, adds tests, and removes dig from the generic _comp_complete_known_hosts registration in bash_completion so installed
dig.bash can take effect instead of always completing only hostnames.

Behavior (completions-core/dig.bash)

  • Switch-style dig: query CLASS, RRTYPE, and NAME may appear in any order, plus +query options and @server
  • One class and one type for completion purposes: after each is set (bare or via -c /-t flags) completion stops offering more classes or types. Meanwhile + options can be multiple.
  • Bare ANY: classified as RRTYPE first (matches dig <NAME> ANY);
  • CHAOS + TXT: suggests fixed *.bind-style names when class is CH and type is TXT.
  • Query names: -q, dotted tokens, or non–class/type-prefix tokens use _comp_compgen_known_hosts where applicable.
  • compopt +o bashdefault +o default to avoid broad default hostname fallback on empty COMPREPLY.
  • @server: ~/.ssh/known_hosts, or BASH_COMPLETION_CMD_DIG_NS_HINTS_FILE for suffix-based hints (longest pattern wins, * defaults; trailing dots on name/pattern normalized). Format documented in comments

Example of $BASH_COMPLETION_CMD_DIG_NS_HINTS_FILE:

# Declare this in `.bashrc` as:
# export BASH_COMPLETION_CMD_DIG_NS_HINTS_FILE=<full_path_to_this_file>

# Glob useful to declare resolvers. Will match always as auto-completion
* 1.1.1.1 8.8.8.8 9.9.9.9 127.0.0.53

# Root zone and COM name servers
. a.root-servers.net. b.root-servers.net. c.root-servers.net. d.root-servers.net. e.root-servers.net. f.root-servers.net. g.root-servers.net. h.root-servers.net. i.root-servers.net. j.root-servers.net. k.root-servers.net. l.root-servers.net. m.root-servers.net.
com a.gtld-servers.net. b.gtld-servers.net. c.gtld-servers.net. d.gtld-servers.net. e.gtld-servers.net. f.gtld-servers.net. g.gtld-servers.net. h.gtld-servers.net. i.gtld-servers.net. j.gtld-servers.net. k.gtld-servers.net. l.gtld-servers.net. m.gtld-servers.net.

# Internal usage
internal.example.com 192.0.2.1 198.51.100.2 203.0.113.3

Note on removing dig from ./bash_completion

Given that dig was registered with _comp_complete_known_hosts, that generic hostname completer took precedence over the lazy-loaded completions-core/dig.bash, so dedicated completion for class, RR type, @server, and + options never ran.

The other option to avoid this case is to add into .bashrc or .bash_profile the load of the dig completion after loading bash-completion with _comp_load (example in macos with brew installation):

[[ -r "${BREWPREFIX:-/opt/homebrew}/etc/profile.d/bash_completion.sh" ]] && . "${BREWPREFIX:-/opt/homebrew}/etc/profile.d/bash_completion.sh"
_comp_load dig 2>/dev/null

Files

File Change
completions-core/dig.bash New dig completion
completions-core/Makefile.am Install dig.bash
bash_completion Stop registering dig with _comp_complete_known_hosts
test/t/test_dig.py Integration tests
test/t/Makefile.am Register test_dig.py

Testing

  • pytest test/t/test_dig.py (cases with require_cmd=True need dig on PATH).

mave007 added 3 commits April 30, 2026 12:52
Signed-off-by: Mauricio Vergara Ereche <mave@cero32.cl>
…ading

Signed-off-by: Mauricio Vergara Ereche <mave@cero32.cl>
Signed-off-by: Mauricio Vergara Ereche <mave@cero32.cl>
Copy link
Copy Markdown
Owner

@scop scop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on making bash completions better. But to verify, did you notice the two few paragraphs of CONTRIBUTING.md as linked in the PR creation view, in particular:

However, before submitting a completion to us, first consider submitting it to the project that ships the commands your completion is for.

If you considered submitting it upstream, let's include the explanation why submit it here instead. If it was asked upstream and rejected there, let's add a link to the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants