* Sourcing bash completion files @ 2015-12-30 23:22 Alarig Le Lay 2015-12-31 1:36 ` Bart Schaefer 2015-12-31 11:19 ` Oliver Kiddle 0 siblings, 2 replies; 6+ messages in thread From: Alarig Le Lay @ 2015-12-30 23:22 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 620 bytes --] Hi, I’m currently using the zsh and bash gentoo packages, so version 5.0.5 and 4.3_p42. 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 But I have an error on the source line: /usr/share/bash-completion/bash_completion:35: parse error near `]]' Here is this file: https://paste.swordarmor.fr/yIHW&ln How can I source this file? Thanks, -- Alarig Le Lay [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Sourcing bash completion files 2015-12-30 23:22 Sourcing bash completion files Alarig Le Lay @ 2015-12-31 1:36 ` Bart Schaefer 2015-12-31 8:17 ` Eric Cook 2015-12-31 11:19 ` Oliver Kiddle 1 sibling, 1 reply; 6+ messages in thread From: Bart Schaefer @ 2015-12-31 1:36 UTC (permalink / raw) To: zsh-users On Dec 31, 12:22am, Alarig Le Lay wrote: } } source /usr/share/bash-completion/bash_completion } } But I have an error on the source line: } /usr/share/bash-completion/bash_completion:35: parse error near `]]' Interesting, it appears bash has adopted the ksh-style @(...) grouping syntax. (Chet will probably confirm or deny.) Try: emulate sh -o kshglob -c 'source /usr/share/bash-completion/bash_completion' ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Sourcing bash completion files 2015-12-31 1:36 ` Bart Schaefer @ 2015-12-31 8:17 ` Eric Cook 2015-12-31 10:30 ` Alarig Le Lay 0 siblings, 1 reply; 6+ messages in thread From: Eric Cook @ 2015-12-31 8:17 UTC (permalink / raw) To: zsh-users On 12/30/2015 08:36 PM, Bart Schaefer wrote: > On Dec 31, 12:22am, Alarig Le Lay wrote: > } > } source /usr/share/bash-completion/bash_completion > } > } But I have an error on the source line: > } /usr/share/bash-completion/bash_completion:35: parse error near `]]' > > Interesting, it appears bash has adopted the ksh-style @(...) grouping > syntax. (Chet will probably confirm or deny.) > > Try: > > emulate sh -o kshglob -c 'source /usr/share/bash-completion/bash_completion' > that error is due to [[ not being able to span across lines. ignoring that, unfortunately that file has a quite a few bashism that just won't work in zsh. an incomplete list: - printf having a -v option (saves the output to a parameter). - relying on parameters like BASH_SOURCE, FUNCNAME - use of the bash builtins shopt, compopt and bind - bash's typeset -F option prints function names where as zsh's typeset -F sets the floating point attribute ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Sourcing bash completion files 2015-12-31 8:17 ` Eric Cook @ 2015-12-31 10:30 ` Alarig Le Lay 0 siblings, 0 replies; 6+ messages in thread From: Alarig Le Lay @ 2015-12-31 10:30 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 1418 bytes --] On Thu Dec 31 03:17:54 2015, Eric Cook wrote: > On 12/30/2015 08:36 PM, Bart Schaefer wrote: > > On Dec 31, 12:22am, Alarig Le Lay wrote: > > } > > } source /usr/share/bash-completion/bash_completion > > } > > } But I have an error on the source line: > > } /usr/share/bash-completion/bash_completion:35: parse error near `]]' > > > > Interesting, it appears bash has adopted the ksh-style @(...) grouping > > syntax. (Chet will probably confirm or deny.) > > > > Try: > > > > emulate sh -o kshglob -c 'source /usr/share/bash-completion/bash_completion' > > > that error is due to [[ not being able to span across lines. > ignoring that, unfortunately that file has a quite a few bashism that just won't work in zsh. > an incomplete list: > - printf having a -v option (saves the output to a parameter). > - relying on parameters like BASH_SOURCE, FUNCNAME > - use of the bash builtins shopt, compopt and bind > - bash's typeset -F option prints function names where as zsh's typeset -F sets the floating point attribute It seems to not work. Regarding to your advices, I put those lines: emulate sh -o kshglob -c 'source /usr/share/bash-completion/bash_completion' 2>/dev/null emulate sh -o kshglob -c 'source /usr/share/bash-completion/completions/ping6' But when I try to complete from ping6 I have an error “command not found: _init_completion” -- Alarig Le Lay [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Sourcing bash completion files 2015-12-30 23:22 Sourcing bash completion files Alarig Le Lay 2015-12-31 1:36 ` Bart Schaefer @ 2015-12-31 11:19 ` Oliver Kiddle 2015-12-31 11:51 ` Alarig Le Lay 1 sibling, 1 reply; 6+ messages in thread From: Oliver Kiddle @ 2015-12-31 11:19 UTC (permalink / raw) To: Alarig Le Lay; +Cc: zsh-users 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Sourcing bash completion files 2015-12-31 11:19 ` Oliver Kiddle @ 2015-12-31 11:51 ` Alarig Le Lay 0 siblings, 0 replies; 6+ messages in thread From: Alarig Le Lay @ 2015-12-31 11:51 UTC (permalink / raw) To: zsh-users [-- Attachment #1: Type: text/plain, Size: 200 bytes --] On Thu Dec 31 12:19:07 2015, Oliver Kiddle wrote: > However, I have attached a rather better native zsh function for dig > completion. It works perfectly, thanks a lot! :) -- Alarig Le Lay [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-12-31 11:51 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-12-30 23:22 Sourcing bash completion files Alarig Le Lay 2015-12-31 1:36 ` Bart Schaefer 2015-12-31 8:17 ` Eric Cook 2015-12-31 10:30 ` Alarig Le Lay 2015-12-31 11:19 ` Oliver Kiddle 2015-12-31 11:51 ` Alarig Le Lay
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).