Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Sourcing bash completion files
- X-seq: zsh-users 21114
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Alarig Le Lay <alarig@xxxxxxxxxxxxx>
- Subject: Re: Sourcing bash completion files
- Date: Thu, 31 Dec 2015 12:19:07 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1451560748; bh=EbGfbkyqCckc7GzRU0uy2N5Q/PI5W4/hdEIXv5YjK9o=; h=cc:In-reply-to:From:References:To:Subject:Date:From:Subject; b=tTkTZE8J+gSTekv7NZWYKtpy0NzV8IuGk870DPkgkOeJ1ecy/Zv58uuPZJv6NQKiKbp+CDjWGXkzNsS+Kj4wRcfx/3UtE8IHeMn0AUfxwKHJ07QRHkCOMk6rYypipUea1BAZeYQGRiZn4EZRjV+kxELNLKVs3dRTZwv5H8cgsdw9X5cpWZ/ii2C5NXmWM3PrXpGuqR6LmaFaJX/mll66lHDJd/k5eHtnhFmD5+k6qY/x79lf++S7g36eT4D3qVhps9yNvLcEBhldxhxkNM5pJIRAUwGMBMi80tN5goZKv1tOgbmu5RoTbHsqihkx33/Iqlevv1G3ujZX9AKfIAdbhg==
- In-reply-to: <20151230232254.GC12070@drscott.swordarmor.fr>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20151230232254.GC12070@drscott.swordarmor.fr>
Alarig Le Lay wrote:
> I would like to source some bash completion files (for exemple for dig,
> I haven't any completion in zsh).
> So, I put this in my ~/.zshrc:
> autoload -U compinit promptinit bashcompinit
> compinit
> promptinit; prompt gentoo
> bashcompinit
> source /usr/share/bash-completion/bash_completion
Without the last line, you'll find that you do then have completion for
many many commands.
If sourcing bash_completion didn't fall over on bashisms and actually
worked, you'd find that it would have replaced many of the zsh
completions with far worse ones. It only makes sense to use bashcompinit
for individual completion functions for specific commands. And that may
still need you to tweak the function and source it from emulate. Its
always better to first check if a proper zsh function is available.
In the case of dig, all the bash_completion script appears to be doing
is enabling hostname completion for it. You can achieve that for zsh
with:
compdef _hosts dig
However, I have attached a rather better native zsh function for dig
completion.
Oliver
diff --git a/Completion/Unix/Command/_dig b/Completion/Unix/Command/_dig
new file mode 100644
index 0000000..2b851c9
--- /dev/null
+++ b/Completion/Unix/Command/_dig
@@ -0,0 +1,85 @@
+#compdef dig
+
+_dns_types() {
+ local expl
+ _description dns-types expl 'DNS type'
+ compadd "$@" "$expl[@]" -M 'm:{a-z}={A-Z}' \
+ ANY A AAAA AFSDB APL AXFR CAA CDNSKEY CDS CERT CNAME DHCID DLV DNAME \
+ DNSKEY DS HIP HINFO IPSECKEY IXFR KEY KX LOC MX NAPTR NS NSEC NSEC3 \
+ NSEC3PARAM OPT PTR RRSIG RP SIG SOA SPF SRV SSHFP TA TKEY TLSA TSIG TXT
+}
+
+local curcontext="$curcontext" state line expl
+local -a alts args
+[[ -prefix + ]] && args=(
+ '*+'{no,}'tcp[use TCP instead of UDP for queries]'
+ '*+'{no,}'ignore[ignore truncation in UDP responses]'
+ '*+domain=[set search list to single domain]:domain:_hosts'
+ '*+'{no,}'search[use search list defined in resolv.conf]'
+ '*+'{no,}'showsearch[show intermediate results in domain search]'
+ '*+'{no,}'aaonly[set aa flag in the query]'
+ '*+'{no,}'adflag[set the AD (authentic data) bit in the query]'
+ '*+'{no,}'cdflag[set the CD (checking disabled) bit in the query]'
+ '*+'{no,}'cl[display the CLASS whening printing the record]'
+ '*+'{no,}'ttlid[display the TTL whening printing the record]'
+ '*+'{no,}'recurse[set the RD (recursion desired) bit in the query]'
+ '*+'{no,}'nssearch[search all authoritative nameservers]'
+ '*+'{no,}'trace[trace delegation down from root]'
+ '*+'{no,}'cmd[print initial comment in output]'
+ '*+'{no,}'short[print terse output]'
+ '*+'{no,}'identify[print IP and port of responder]'
+ '*+'{no,}'comments[print comment lines in output]'
+ '*+'{no,}'stats[print statistics]'
+ '*+'{no,}'qr[print query as it was sent]'
+ '*+'{no,}'question[print question section of a query]'
+ '*+'{no,}'answer[print answer section of a reply]'
+ '*+'{no,}'authority[print authority section of a reply]'
+ '*+'{no,}'additional[print additional section of a reply]'
+ '*+'{no,}'all[set all print/display flags]'
+ '*+time=[set query timeout]:timeout (seconds)'
+ '*+tries=[specify number of UDP query attempts]:tries'
+ '*+retry=[specify number of UDP query retries]:retries'
+ '*+ndots=[specify number of dots to be considered absolute]:dots'
+ '*+bufsize=[specify UDP buffer size]:size (bytes)'
+ '*+edns=[specify EDNS version for query]:version (0-255)'
+ '*+noedns[clean EDNS version]'
+ '*+'{no,}'multiline[verbose multi-line output]'
+ '*+'{no,}'onesoa[AXFR prints only one soa record]'
+ '*+'{no,}"fail[don't try next server on SERVFAIL]"
+ '*+'{no,}'besteffort[try to parse even malformed messages]'
+ '*+'{no,}'dnssec[request DNSSEC records]'
+ '*+'{no,}'sigchase[chase DNSSEC signature chains]'
+ '*+trusted-key=[specify file conrtaing trusted kets]:file:_files'
+ '*+'{no,}'topdown[do DNSSEC validation in top down mode]'
+ '*+'{no,}'nsid[include EDNS name server ID request in query]'
+)
+_arguments -s -C $args \
+ '(- *)-h[display help information]' \
+ '(- *)-v[display version information]' \
+ '*-c+[specify class]:class:compadd -M "m:{a-z}={A-Z}" - IN CS CH HS' \
+ '*-b+[specify source IP]:IP' \
+ '*-f+[batch mode, read arguments from file]:file:_files' \
+ '*-m[enable memory usage debugging]' \
+ '*-p+[specify port number]:port:_ports' \
+ '*-4[use IPv4 only]' \
+ '*-6[use IPv6 only]' \
+ '*-t+[specify type]:type:_dns_types' \
+ '*-q+[specify host name to query]:host:_hosts' \
+ '*-x+[reverse lookup]:IP address' \
+ '*-k+[specify TSIG key file]:file:_files' \
+ '*-y+[specify TSIG key]:hmac\:name\:key' \
+ '*: :->args' && ret=0
+
+if [[ -n $state ]]; then
+ if compset -P @; then
+ _wanted hosts expl 'DNS server' _hosts && ret=0;
+ else
+ case $#line in
+ <3->) alts+=( 'classes:query class:compadd -M "m:{a-z}={A-Z}" - IN CS CH HS' ) ;&
+ 2) alts+=( 'types:query type:_dns_types' ) ;;
+ esac
+ _alternative 'hosts:host:_hosts' $alts && ret=0
+ fi
+fi
+
+return ret
Messages sorted by:
Reverse Date,
Date,
Thread,
Author