From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25451 invoked by alias); 3 Jun 2018 00:12:41 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42920 Received: (qmail 18218 invoked by uid 1010); 3 Jun 2018 00:12:41 -0000 X-Qmail-Scanner-Diagnostics: from park01.gkg.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(205.235.26.22):SA:0(-1.4/5.0):. Processed in 3.539834 secs); 03 Jun 2018 00:12:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: SRS0=a/H0=IU=yahoo.co.uk=okiddle@bounces.park01.gkg.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: by amavisd-new at gkg.net Authentication-Results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1527980016; bh=l+xb/o70MihcdH1fO8kITpWKjBVTsaG3LFq3hElQFPQ=; h=From:To:Subject:Date:From:Subject; b=OMhMUylpyyLJXIJhvifS1HggDHCdMm0QTTbwdVVaCh/Rq8pnM/lJcAOnpmj++FVjshxK0ZLG/S2t1rfZu9yy+NmBcstgkmSILH5USL6bwHqpI1u0+N6E7GUMRuvRr9M5bXbq0VWElVrQsxgrvj21d6XqeePD0V6XpNRUQcAwUorO0TEz/CdGwtbMeKdhARyZf++9iTqggJvHHz9TH3xeHEdNoK++xv2JEH1tkO4KdNM42dhvAtdRm4XV6RtJo9JkgWdjDHPMpJ32pCW8PfDjJdzYdupOTGlIlIlElqB+VMGnnf/SdiXlynZdhNnfNs97z9q+HKvmmTcpm0JuAjT1Qg== X-YMail-OSG: EnyM_woVM1lkrThux1WKpFdSEwGJ1JCJ95Un2stbust65dPBvH7LwPKaPUzxNqo ih8Dj4xBHP1eMeRK7BEgwmcZMl7nM2H8CX9zKWyB1Z5hSHsvn0V.sMEKgqG0fIz3qMF6V6x44wwZ SrNEnRejRjb1CwRKVltJLkLYlaaFqvEiahknGprOdG0Sd8IMSPe6saDjuK42Ox0CEcYVlj0x0DHS 2Em3qKh9ggSui9zIkS5e7n3VcJ0pe.Y4iG9BrzrQ15ehYffcFaMZ3uLmk09iR3D5TSxumTd31eOO zTTPkbLSyhKbNxz.1DedVBhPciD0a67VvfHza2XGwePt7z_0L7bEWKXvQYWxu5E9CGETW43aDgHw XkkE0Qv7zC5lXXAQHqQKqto2UDGC.zDv3HGEZ7rd8uChu3zt2x6wztxDOvTGcAFFBTiuJ2lya8VI TQF0JaCPK3bHXOxWnI_I2jgUxrw91SUQNktPzscNyG9rqdWZ9mR9ZiEr3D2oSGxSxPsvgLTxcb40 wWRnW2BsB2sXawISm4w9zdSyXeX_sFfNFMwaFl.FTuqI9mqsVe3keshmbiUN7qT3btpfC1WidLRm _kkt6P9VaHjpidZ.LeU8Ja5jAwsCSu4pR_8PDIbezZxx0Be901oOyxxlUMdPkVzKiUfiS3ELGYT1 AcK2DlWDcNJuySxJN From: Oliver Kiddle To: Zsh workers Subject: PATCH: new dkms completion MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13101.1527980012.1@thecus> Date: Sun, 03 Jun 2018 00:53:32 +0200 Message-ID: <13102.1527980012@thecus> This adds completion for dkms. dkms takes subcommands but options can be specified either before or after the subcommands. This takes the approach of marking some of the more obscure options with ! if a subcommand has yet to be specified. Subcommands are also filtered based on earlier options. For module/version, I used _multi_parts -i. The documented effect of -i is to allow it to insert multiple separators. So you might assume that it has no effect when there can only be one separator. However, it seems to allow it to insert the full match in one go: z completes directly to 'zfs/0.7.9' rather than stopping at the / which is useful because it is common to only have one version of the modules installed. Oliver diff --git a/Completion/Linux/Command/_dkms b/Completion/Linux/Command/_dkms new file mode 100644 index 000000000..7ea34aa2e --- /dev/null +++ b/Completion/Linux/Command/_dkms @@ -0,0 +1,162 @@ +#compdef dkms + +local curcontext="$curcontext" ign cmds opts ret=1 +local -a state line expl args subcmds dirs +local -A opt_args + +subcmds=( + 'add:add a module/version combination to the tree for builds and installs' + 'remove:remove a module from the tree' + 'build:compile a module for a kernel' + "install:install a build module for it's corresponding kernel" + 'uninstall:uninstall a module for a kernel' + 'match:install every module that is installed for a template kernel for another kernel' + 'mkdriverdisk:create a floppy driver disk image for use when updated drivers are needed to install an OS' + 'mktarball:tar up files in the DKMS tree for a specific module' + 'ldtarball:extract a tarball created with mktarball into the DKMS tree' + 'mkrpm:create an RPM package for a module' + 'mkdeb:create a debian binary package for a module' + 'mkdsc:create a debian source package for a module' + 'mkkmp:create a Kernel Module Package source RPM for a module' + 'status:display the current status of modules, versions and kernels within the tree' + 'autoinstall:try to install the latest revision of all modules that have been installed for other kernel revisions' +) + +args=( + '(1)-m[specify module]:module:->modules' + '(1)-v[specify module version]:version' + '(-q --quiet)'{-q,--quiet}'[suppress output]' + '(--all)*'{-a,--arch}'[specify system architecture]:architecture:->architectures' + '*--directive=:directive' + '--dkmstree=:path:_directories' + '--installtree=:path:_directories' + '--sourcetree=:path:_directories' + '--dkmsframework=:path:_directories' + '1: : _describe -t commands command subcmds' +) + +cmd=${${${subcmds%%:*}:*words}[1]} +if [[ -n $cmd ]]; then + curcontext="${curcontext%:*}-$cmd:" +else + # exclude sub-commands based on any options specified so far + for cmds opts in \ + '(remove|build|install|uninstall|match|status|mk(^kmp))' 'k' \ + '(add|remove)' '-rpm_safe_upgrade' \ + 'mk(driverdisk|kmp)' '-spec' \ + 'mk(deb|dsc|rpm)' '-legacy-postinst' \ + 'mk(tarball|rpm|deb|dsc)' '-(source|binary)-only' \ + '(match|build|mkkmp)' '(k|-no-(prepare|clean)-kernel|-kernelsourcedir)' \ + '(|un)install' '-no-(depmod|initrd)' \ + 'mkdriverdisk' '([dr]|-distro|-release|-size|-media)' \ + '(add|build|install|ldtarball)' '-force' \ + 'match' '-templatekernel' \ + '*tarball' '-archive' \ + '(match|build|mkkmp)' '(j*|-no-(prepare|clean)-kernel|-kernelsourcedir)' \ + '(remove|build|install|status|mk(^kmp))' '-all' \ + 'build' '-config' + do + [[ -n ${(M)words:#-${~opts}*} ]] && + subcmds=( ${(M)subcmds:#${~cmds}:*} ) + done + args+=( '(1 -)'{-V,--version}'[display version information]' ) + ign='!' # hide some uncommon options but handle their arguments +fi + +case $cmd in + remove|build|install|uninstall|mk*|status) + args+=( ': :->modules' ) + ;| + |remove|build|install|uninstall|match|status|mk(^kmp)) + args+=( '(--all)*-k[specify kernel version]:kernel:->kernels' ) + ;| + |add|remove) args+=( "${ign}--rpm_safe_upgrade" ) ;| + |mk(driverdisk|kmp)) + args+=( "${ign}--spec=:spec file:_files -g '*.spec(-.)'" ) + ;| + |(mk|ld)tarball) + args+=( "${ign}--archive=:tarball:_files -g '*.tar(-.)'" ) + ;| + |mk(deb|dsc|rpm)) + args+=( "${ign}--legacy-postinst=:value [1]:(0 1)" ) + ;| + |mk(tarball|rpm|deb|dsc)) args+=( "${ign}(--source-only --binaries-only)--"{source,binaries}-only ) ;| + |match|build|mkkmp) + args+=( #TODO: check ignore needed in absence of parameters + "${ign}--no-prepare-kernel" + "${ign}--no-clean-kernel" + '--kernelsourcedir=:directory:_directories' + "${ign}-j+[specify maximum number of jobs to use when building]:jobs" + ) + ;| + |(|un)install) + args+=( + "${ign}--no-depmod" + "${ign}--no-initrd" + ) + ;| + |add) + args+=( + '-c[specify location of dkms.conf file]:location:_files' + ) + ;| + |remove|build|install|status|mk(^kmp)) + args+=( '(-a --arch -k)--all[specify all relevant kernels/arches]' ) + ;| + |build) + args+=( "${ign}--config=:kernel config file:_files" ) + ;| + |add|build|install|ldtarball) + args+=( '--force[force overwriting of extant files]' ) + ;| + |match) + args+=( "${ign}--templatekernel=:kernel:->kernels" ) + ;| + |mkdriverdisk) + args+=( + "${ign}(-d --distro)"{-d,--distro=}':distribution:(redhat'{,1,2,3}' suse unitedlinux)' + "${ign}(-r --release)"{-r,--release=}':release' + "${ign}--size=:size (kb) [1440]" + "${ign}--media=:media type [floppy]:(floppy iso tar)" + ) + ;| + add) + args+=( + '2:path:_directories' + '3:tarball:_files -g "*.tar(-.)"' + ) + ;; + install) + args+=( + '2:rpm file:_files -g "*.rpm(-.)"' + ) + ;; +esac + +_arguments -C $args && ret=0 + +case $state in + modules) + dirs=( ${(e)opt_args[--dkmstree]:-/var/lib/dkms}/*/*(/) ) + dirs=( ${${(M)dirs%/*/*}#/} ) + _description modules expl module + _multi_parts -i "$expl[@]" / dirs && ret=0 + ;; + kernels) + if compset -P 1 '*/'; then + _description architectures expl architecture + compadd "$expl[@]" /lib/modules/$IPREFIX/build/arch/*(/:t) && ret=0 + else + compset -S '/*' + dirs=( /lib/modules/*(/:t) ) + _description -V kernels expl kernel + compadd "$expl[@]" -r "/ \t\n\-" ${(on)dirs} && ret=0 + fi + ;; + architectures) + _description architectures expl architecture + compadd "$expl[@]" /lib/modules/$(uname -r)/build/arch/*(/:t) && ret=0 + ;; +esac + +return ret