From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9098 invoked by alias); 31 Dec 2015 11:25:19 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21114 Received: (qmail 6852 invoked from network); 31 Dec 2015 11:25:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MALFORMED_FREEMAIL,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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== X-Yahoo-Newman-Id: 578759.70155.bm@smtp119.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: LIMq8IgVM1l03sQ7BcxjkblEW61daY6IT_UaC1UA78LCFUT 2JTQTthP3ZZbtyih3vXQHhOuLev.sISQhhNwRGb3HOznUsdNRDaAtZwKNnOc ravEQQNoOQu2ptw1.1uwG0PgygT_v0tUdogTQounCQgNfBiC7Ud8L7qQgNCN qM1t6Fz6ddQTtd9IKKmgJFmZYWPaiKpSwPQ4nsNPcTsSG1s2Kq6RKPGRz7vf Yh.V56HWimiVWxRbLhgCpczWn7gZlQr2O21ObyHjK.WbmGpsYnUZ4CZg9H0N _JCdm5e4r0GLfpSeGKhc3MsmuBY_zNAgPzNJsmBWW9QqzG4uGVDBxaFoTYkG 1wUPg2kwvr_KSxC29tz_RYUqiI6gKfNdK6ZBTvSK4qbumo3A7ADSG9tDIH8D KzNk4tVfVsgqtz64q2KT5wPdV7Dcmvs0m5rZMg9NY8etzNtKLH2nknrtV2sf TJwXWccwKa.bCgv3w_hRU4cTuIr1XtaWVjqRS7UQQ4jQVtTnH9wzdqQO6Puz nL2XxFlFaQBKvQAdj3LpBJ4SWpwyMKYng X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- cc: zsh-users@zsh.org In-reply-to: <20151230232254.GC12070@drscott.swordarmor.fr> From: Oliver Kiddle References: <20151230232254.GC12070@drscott.swordarmor.fr> To: Alarig Le Lay Subject: Re: Sourcing bash completion files MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22297.1451560692.1@thecus.kiddle.eu> Date: Thu, 31 Dec 2015 12:19:07 +0100 Message-ID: <22300.1451560747@thecus.kiddle.eu> 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