From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 896 invoked by alias); 4 Jun 2018 15:04:35 -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: 42931 Received: (qmail 874 invoked by uid 1010); 4 Jun 2018 15:04:35 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f51.google.com 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(209.85.214.51):SA:0(-1.9/5.0):. Processed in 2.65788 secs); 04 Jun 2018 15:04:35 -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.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=LggMSwypoz8nZMT182hcL6BSGmCoObu6xsv0/3osIFY=; b=yxpOhmY6gk04OVpkLBiiO76XpuQ+xs3hpSXvQkVZg6/5OMmRiYPvSRCEIx9V3Blno8 cIAkaas8xsFUrgYZMIHRvCP2h/UV/3YabnJwQ8YcY1eBH0nbpf9KnOZ/Gdrs8gImhDpi stLuU/Jhe6LPp2suuQMlUH7D3fPSNgMOtOW0vMzsIMcQCmJMnBW2zehaPEqkMywiHweL 8mlGjNEjESx+xZJQWiOFSB1k1Ub7pVoeOYtP9P0MWpu2ZB3bYYvk/uoJa0WxYmKQp0sx 7sCNFvT9OIGYXoIFPBl/cHIWqW2YURgJgsEWbd+ziZ0IkafOitAdwnuAV1w9wfhWQgbT egGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=LggMSwypoz8nZMT182hcL6BSGmCoObu6xsv0/3osIFY=; b=uQrCDbYYv3c9+CJk/SpK+yQ9jFi8CunUuHgIHz39nYA5OHFHf/6q4fex6SIvcF7xU1 mSXU19VrwWt2ceMqQrX98xmkNc7c3+s9w/5sGiXsDFnDYqvEvVeg3PMGTEeXaiAjKVLA HMQ96ZNkn5KGmCfkNdxe5Sh7nXq3XxDjfZiKdFw2xAlz970avbogawMteISYa7amxdwv oKmRZCbAqV3KW5KLPawVP7j+7gg9XILu3GdKqk+xhcbC2vL03DWg0yxldJ3tLgji7zFW fXWimnxWzNzGFaUV49M2WyLvoa+K06ttNbfd/R+nsPzCgnWw8nVKdUwndU/DZD6sFMsv Wg0g== X-Gm-Message-State: APt69E1IgUDuZ++OhKfbCmH1qVYS80uL2m/F40YEhGNYZ2Uuap1F+ldj 3vluWw7bwzvWAy8/hzk8Jw2mkeQPgoY= X-Google-Smtp-Source: ADUXVKJ+tZO1qjQ2WaMuOgyJRrX4qtdOQ0FSB6To2dFR9jhNyu33mnNXvmPGVN2cw22TzVXJprtGog== X-Received: by 2002:a24:9d0a:: with SMTP id f10-v6mr13888382itd.61.1528124669654; Mon, 04 Jun 2018 08:04:29 -0700 (PDT) From: dana Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.18\)) Subject: [PATCH] Completion: Add 6 new functions, update _cksum and _md5sum Message-Id: <01E3D78F-D56D-4513-B922-5E93C1C0667C@dana.is> Date: Mon, 4 Jun 2018 10:04:27 -0500 To: Zsh workers X-Mailer: Apple Mail (2.3445.6.18) Hi again, Here's another batch of relatively easy completion changes. ADDED functions for the following (all under Unix): * base64, base32 * chroot * lz4, lz4c, lz4c32, lz4cat, unlz4 * readlink * shasum * tee UPDATED the following functions: * _cksum =E2=80=94 This previously covered the BSD versions of cksum, = sum, and related digest tools like md5 and sha1. I've made the following changes: * Support GNU cksum and sum * Support Darwin cksum, sum, and md5 * Support the skein* tools added to FreeBSD in 2016 * Don't support OpenBSD sum (purged in 2014) * Don't complete Dragonfly/FreeBSD sum as cksum (sum takes no options) * Fix some option presence/exclusivity issues * Fix several typos * Move file from BSD to Unix (since its purpose has expanded) (I was actually going to let the GNU tools have Unix/*/_cksum and move = the BSD ones to BSD/*/_md5, since that's the canonical name for all of them in = the *BSD source trees, but you can't have cksum/sum in two different = files, so... this is my solution.) * _md5sum =E2=80=94 This previously covered the GNU md5sum tool. I've = made the following changes: * Support b2sum, sha1sum, sha256sum, sha384sum, sha512sum * Fix some option presence/exclusivity issues * Clean up / clarify wording As usual, let me know if i've done anything silly. dana diff --git a/Completion/Unix/Command/_base64 = b/Completion/Unix/Command/_base64 new file mode 100644 index 000000000..0867919a9 --- /dev/null +++ b/Completion/Unix/Command/_base64 @@ -0,0 +1,59 @@ +#compdef base64 gbase64 base32 gbase32 + +# Note: This does NOT cover `uuencode`/`uudecode`, which on some BSD = systems +# have the aliases `b64encode`/`b64decode` =E2=80=94 those are = sufficiently different +# that they belong in another function. It DOES cover GNU's `base32`, = since it +# is essentially the same program as their `base64`. + +local variant type=3Dbase${service//[^2346]/} + +_pick_variant -r variant \ + gnu=3D'Free Soft' fourmilab=3Dfourmi darwin=3D-D unix --version + +case $variant in + gnu) + _arguments -s -S : \ + '(: -)--help[display help information]' \ + '(: -)--version[display version information]' \ + + dec \ + '(enc -d --decode)'{-d,--decode}"[decode input from $type]" \ + '(enc -i --ignore-garbage)'{-i,--ignore-garbage}'[ignore = irrelevant characters when decoding]' \ + + '(enc)' \ + '(dec)'{-w+,--wrap=3D}'[wrap encoded lines at specified number of = columns]:number of columns' \ + + in \ + '1:input file:_files' + return + ;; + darwin) + _arguments -s -S : \ + '(: -)'{-h,--help}'[display help information]' \ + + '(dec)' \ + '(enc)'{-D,--decode}"[decode input from $type]" \ + + '(enc)' \ + '(dec)'{-b+,--break=3D}'[wrap encoded lines at specified number = of columns]:number of columns' \ + + '(out)' \ + {-o+,--output=3D}'[specify output file]:output file:_files' \ + + '(in)' \ + {-i+,--input=3D}'[specify input file]:input file:_files' \ + '1:input file:_files' + return + ;; + fourmilab) + _arguments -s -S : \ + '(: -)--copyright[display copyright information]' \ + '(: -)'{-u,--help}'[display help information]' \ + '(: -)--version[display version information]' \ + + dec \ + '(enc -d --decode)'{-d,--decode}"[decode input from $type]" \ + '(enc -n --noerrcheck)'{-n,--noerrcheck}'[ignore errors when = decoding]' \ + + '(enc)' \ + '(dec)'{-e,--encode}"[encode input to $type]" \ + + io \ + '1:input file:_files' \ + '2:output file:_files' + return + ;; +esac + +# A few other implementations exist, though they are rarely encountered +_default diff --git a/Completion/Unix/Command/_chroot = b/Completion/Unix/Command/_chroot new file mode 100644 index 000000000..516992694 --- /dev/null +++ b/Completion/Unix/Command/_chroot @@ -0,0 +1,53 @@ +#compdef chroot gchroot + +local variant ret=3D1 +local -a context line state state_descr args +local -A opt_args + +_pick_variant -r variant gnu=3D'Free Soft' unix --version + +variant+=3D-$OSTYPE + +case $variant in + gnu-*) + args=3D( + '(: -)--help[display help information]' + '(: -)--version[display version information]' + '--groups=3D[specify supplemental group memberships]: :_sequence = -s , _groups' + '--userspec=3D[specify user and group to run process as]: = :->userspecs' + '--skip-chdir[do not change working directory to /]' + ) + ;; + *-openbsd*) + args=3D( + '-u+[specify user to run process as]: :_users' + '-g+[specify group to run process as, and supplemental group = memberships]: :_sequence -s , _groups' + ) + ;; + *-(darwin|dragonfly|freebsd|netbsd)*) + args=3D( + '-u+[specify user to run process as]: :_users' + '-g+[specify group to run process as]: :_groups' + '-G+[specify supplemental group memberships]: :_sequence -s , = _groups' + ) + ;; +esac + +args+=3D( '1:new root directory:_directories' '*:::command:_normal' ) + +_arguments -s -S : $args && ret=3D0 + +# @todo user:group specs are probably used often enough to justify = making a type +# function for this (see also `chown`, `cpio`, `rsync`, ...) +[[ $state =3D=3D userspecs ]] && +if compset -P '*:*:'; then + ret=3D1 +elif compset -P '*:'; then + _groups && ret=3D0 +elif compset -S ':*'; then + _users && ret=3D0 +else + _users -qS : && ret=3D0 +fi + +return ret diff --git a/Completion/Unix/Command/_lz4 b/Completion/Unix/Command/_lz4 new file mode 100644 index 000000000..d8541e8a6 --- /dev/null +++ b/Completion/Unix/Command/_lz4 @@ -0,0 +1,103 @@ +#compdef lz4 lz4c lz4c32 lz4cat unlz4 + +# Notes: +# - All lz4 CLI tools take the same options =E2=80=94 you can do `unlz4 = --compress` if +# you want =E2=80=94 and we complete accordingly. One can make a = reasonable argument +# that we shouldn't, but...? +# - The only exceptions to the above are the legacy compression options = (-c0, +# -hc, and so on) =E2=80=94 only lz4c accepts these. Each of these = options is +# interpreted separately otherwise (e.g., -c0 becomes equivalent to = -c -0) +# - All these tools use a non-standard option-handling method that we = don't +# fully support. For example, the tool will let you do things like = `-b1e3i3` +# instead of `-b1 -e3 -i3` =E2=80=94 we won't + +local ret=3D1 +local -a context line state state_descr expl args levels=3D( -{1..16} ) +local -A opt_args val_args + +args=3D( + + excl # Fully exclusive options + '(: -)'{-h,--help}'[display help information]' + '(: -)-H[display long help information]' + '(: -)'{-V,--version}'[display version information]' + + misc # Misc. arguments + '(-q -v --quiet --verbose)*'{-q,--quiet}'[reduce output verbosity]' + '(-q -v --quiet --verbose)*'{-v,--verbose}'[increase output = verbosity]' + '*::: :->files' + + B # Benchmark/compress-mode options (not allowed with legacy = format) + '(d t -l)*-B-[specify block property]: :->block-props' + '(d t -l --no-content-size)--content-size[record original = uncompressed size]' + '(d t -l --no-frame-crc)--frame-crc[enable content checksum]' + '(d t -l --content-size)--no-content-size[do not record original = uncompressed size]' + '(d t -l --frame-crc)--no-frame-crc[disable content checksum]' + '(d t -l --sparse)--no-sparse[disable sparse-file support]' + '(d t -l --no-sparse)--sparse[enable sparse-file support]' + + C # Compress/decompress-mode options + '(b t -c --stdout --to-stdout)'{-c,--stdout}'[write on standard = output]' + '(b t -y)'{-f,--force}'[overwrite target without prompting, or cat on = standard output]' + '(b t -k --keep --rm)'{-k,--keep}'[keep source file]' + '(b t -m -r --multiple)'{-m,--multiple}'[take multiple input files]' + '!(b -t -f -y --force)--no-force' + '(b t -m --multiple)-r[operate recursively on directories]' + '(b t -k --keep)--rm[remove source file]' + '!(b t -c --stdout)--to-stdout' + + b # Benchmark-mode options + "(C c d t)-b-[benchmark file using specified compression = level]::compression level:(${(j< >)levels//-/})" + "(C c d t)-e-[specify upper compression level limit (with = -b)]:compression level:(${(j< >)levels//-/})" + '(C c d t)-i-[specifiy minimum evaluation time (with -b)]:evaluation = time (seconds)' + + c # Compress-mode options + "(b d t ${(j< >)levels} -c0 -c1 -c2 -hc)"${^levels} + '(B b d t -m -r --multiple)-l[compress using legacy (Linux kernel) = format]' + '(b d t -z --compress)'{-z,--compress}'[compress file]' + + d # Decompress-mode options + '(B b c d t)'{-d,--decompress}'[decompress file]' + '!(B b c d t)--uncompress' + + t # Test-mode options + '(B C b c d t)'{-t,--test}'[test integrity of compressed file]' +) +[[ $service =3D=3D lz4c ]] && args+=3D( + + l # Legacy compress-mode options (not to be confused with the = legacy format) + "(b d t ${(j< >)levels} -c1 -c2 -hc)-c0[use fast compression (like = -0)]" + "(b d t ${(j< >)levels} -c0 -c2 -hc)-c1[use high compression (like = -9)]" + "(b d t ${(j< >)levels} -c0 -c1 -c2 -hc)"{-c2,-hc}'[use very high = compression (like -12)]' + '(b t -f --force)-y[overwrite target without prompting]' +) + +_arguments -s -S : $args && ret=3D0 + +case $state in + block-props) + # The usage help indicates that the use of an explicit byte value = (-B32 or + # greater) is only for benchmarking, and indeed when such a value = is given + # the tool prints a message prefixed with 'bench:'... but there is = nothing + # that actually restricts this to the benchmark mode, so...? + _values 'predefined block property or block size in bytes (32+)' \ + '4[set block size to 64 KiB]' \ + '5[set block size to 256 KiB]' \ + '6[set block size to 1 MiB]' \ + '7[set block size to 4 MiB]' \ + 'D[enable block dependency]' \ + 'X[enable block checksum]' \ + && ret=3D0 + ;; + files) + if + (( CURRENT =3D=3D 1 )) || + [[ -n ${opt_args[(i)*-(-b|-m|-r|--multiple)]} ]] + then + if [[ -n ${opt_args[(i)*--r]} ]]; then + _description files expl 'input file or directory' + else + _description files expl 'input file' + fi + _files "${(@)expl}" && ret=3D0 + elif (( CURRENT =3D=3D 2 )); then + _description files expl 'output file' + _files "${(@)expl}" && ret=3D0 + else + _message 'no more arguments' && ret=3D0 + fi + ;; +esac + +return ret diff --git a/Completion/Unix/Command/_readlink = b/Completion/Unix/Command/_readlink new file mode 100644 index 000000000..36bd43752 --- /dev/null +++ b/Completion/Unix/Command/_readlink @@ -0,0 +1,48 @@ +#compdef readlink greadlink + +local variant ret=3D1 +local -a context line state state_descr args copts aopts=3D( -A '-*' ) +local -A opt_args + +# We can't use groups here because it would complicate the option = filtering +copts=3D( -e -f -m --canonicalize --canonicalize-existing = --canonicalize-missing ) + +args=3D( + '(: -)--help[display help information]' + '(: -)--version[display version information]' + # Delimiter options + # (Note: GNU `readlink` won't let you use -n with multiple files) + '(-n -z --no-newline --zero)'{-n,--no-newline}'[suppress trailing = newline]' + '(-n -z --no-newline --zero)'{-z,--zero}'[use NUL as output = delimiter]' + # Verbosity options + '(-q -s -v --quiet --silent = --verbose)'{-q,-s,--quiet,--silent}'[suppress most error messages]' + '(-q -s -v --quiet --silent --verbose)'{-v,--verbose}'[show error = messages]' + # Canonicalisation options + "(${(j< >)copts})"{-e,--canonicalize-existing}'[canonicalize paths = (all components must exist)]' + "(${(j< >)copts})"{-f,--canonicalize}'[canonicalize paths]' + "(${(j< >)copts})"{-m,--canonicalize-missing}'[canonicalize paths = (components may be missing)]' +) + +# Filter out non-GNU options if applicable +if _pick_variant gnu=3D'Free Soft' unix --version; then + aopts=3D( ) +else + case $OSTYPE in + darwin*) args=3D( ${(@M)args:#(|*\))-[n]\[*} ) ;; + netbsd*) args=3D( ${(@M)args:#(|*\))-[fnqsv]\[*} ) ;; + dragonfly*|*bsd*) args=3D( ${(@M)args:#(|*\))-[fn]\[*} ) ;; + *) args=3D( ) ;; + esac +fi + +_arguments -s -S $aopts : $args '*: :->files' && ret=3D0 + +# File arguments must be symlinks unless a canonicalisation option is = given +[[ $state =3D=3D files ]] && +if [[ ${opt_args[(i)(${~${(j<|>)copts}})]} ]]; then + _files && ret=3D0 +else + _files -g '*(@)' && ret=3D0 +fi + +return ret diff --git a/Completion/Unix/Command/_shasum = b/Completion/Unix/Command/_shasum new file mode 100644 index 000000000..950a47763 --- /dev/null +++ b/Completion/Unix/Command/_shasum @@ -0,0 +1,24 @@ +#compdef shasum -P shasum(|5).* + +# This function covers the `shasum` script included with Perl (and = notably the +# primary SHA digest tool on macOS). See `_md5sum` for the GNU digest = utilities +# and `_cksum` for the BSD ones. +# +# @todo It's possible that someone could symlink this script to = `sha1sum` or +# whatever; we might want to detect that some day. + +_arguments -s -S : \ + '(: -)'{-h,--help}'[display help information]' \ + '(: -)'{-v,--version}'[display version information]' \ + + '(sum)' \ + '(chk)'{-0,--01}'[read in BITS mode]' \ + '(chk)'{-b,--binary}'[read in binary mode]' \ + '(chk)'{-p,--portable}'[read in portable mode]' \ + '(chk)'{-t,--text}'[read in text mode]' \ + + 'chk' \ + '(sum)'{-c,--check}'[verify checksums from input files]' \ + '(sum -s -w --status --warn)'{-s,--status}'[suppress all output]' \ + '(sum -s -w --status --warn)'{-w,--warn}'[warn about each improperly = formatted checksum line]' \ + + misc \ + '(-a --algorithm)'{-a+,--algorithm=3D}'[specify = algorithm]:algorithm:(1 224 256 384 512 512224 512256)' \ + '*: :_files' diff --git a/Completion/Unix/Command/_tee b/Completion/Unix/Command/_tee new file mode 100644 index 000000000..66ef66e19 --- /dev/null +++ b/Completion/Unix/Command/_tee @@ -0,0 +1,32 @@ +#compdef tee gtee + +local ret=3D1 +local -a context line state state_descr args +local -A opt_args + +args=3D( + '(: -)--help[display help information]' + '(: -)--version[display version information]' + '(-a --append)'{-a,--append}'[append to files instead of = overwriting]' + '(-i --ignore-interrupts)'{-i,--ignore-interrupts}'[ignore interrupt = signals]' + '(--output-error)-p[warn on errors writing to non-pipes]' + '(-p)--output-error=3D[specify write-error behavior]: :->errmodes' +) + +# Filter out non-GNU options if applicable +_pick_variant gnu=3D'Free Soft' unix --version || +args=3D( ${(@M)args:#(|*\))-[ai]\[*} ) + +_arguments -s -S : $args '*: :_files' && ret=3D0 + +[[ $state =3D=3D errmodes ]] && { + args=3D( + 'exit[exit on errors writing to any output]' + 'exit-nopipe[exit on errors writing to non-pipes]' + 'warn[warn on errors writing to any output]' + 'warn-nopipe[warn on errors writing to non-pipes]' + ) + _values 'error mode' $args && ret=3D0 +} + +return ret diff --git a/Completion/BSD/Command/_cksum = b/Completion/BSD/Command/_cksum deleted file mode 100644 index 4f5b68d8a..000000000 --- a/Completion/BSD/Command/_cksum +++ /dev/null @@ -1,67 +0,0 @@ -#compdef cksum sum=3Dcksum md2 md4 md5 rmd160 sha1 sha256 sha384 sha512 = sha512t256 - -if [[ $OSTYPE =3D=3D (dragonfly|freebsd)* && service =3D=3D cksum ]]; = then - _arguments -s -S -A '-*' \ - '-o[use specified historic algorithm]:historic algorithm:(1 2 3)' \ - '*:_files' - -else - local -a args - - case $OSTYPE in - dragonfly*|freebsd*|netbsd*) - args+=3D( - '-t[run built-in time trial]' - ) - ;| - dragonfly*|freebsd*|openbsd*) - args+=3D( - '-r[reverse the output format]' - ) - ;| - dragonfly*) - args+=3D( - '-b+[begin at specified offset]:begin offset: ' - '-e+[end at specified offset]:end offset: ' - ) - ;; - freebsd*) - args+=3D( - '-c+[compare digest against specified string]:digest string: ' - ) - ;; - netbsd*) - args+=3D( - '(*)-c+[compare checksums against specifed = sumfile]:sumfile:_files' - '-n[reverse the output format]' - '-w[warn on malformed checksum files]' - ) - if [[ $service =3D=3D cksum ]]; then - args=3D( - '(-o)-a+[use the specfied algorithm(s)]:algorithm:(crc md2 = md4 md5 old1 old2 rmd160 sha1 sha256 sha384 sha512)' - '(-a)-o+[use the specfied historic algorithm]:historic = algorithm:(1 2)' - ) - fi - ;; - openbsd*) - args+=3D( - '-b[output in base 64]' - '-C+[compare checksums against specifed = checklist]:checklist:_files' - '-c[file arguments are checklists]' - '-h+[output to specified hashfile]:hashfile:_files' - '*-t[run built-in time trial]' - ) - if [[ $service =3D=3D cksum ]]; then - args+=3D('*-a+[use the specfied algorithm(s)]:algorithm:_values = -s , algotithm cksum md5 rmd160 sha1 sha224 sha256 sha384 sha512/256 = sha512') - fi - ;; - esac - - _arguments -s -S -A '-*' \ - $args \ - '-p[echo stdin to stdout]' \ - '-q[quiet mode]' \ - '-s+[checksum specified string]:string: ' \ - '-x[run built-in test]' \ - '*:_files' -fi diff --git a/Completion/Unix/Command/_cksum = b/Completion/Unix/Command/_cksum new file mode 100644 index 000000000..625e3003f --- /dev/null +++ b/Completion/Unix/Command/_cksum @@ -0,0 +1,112 @@ +#compdef cksum gcksum sum gsum md2 md4 md5 rmd160 sha1 sha256 sha384 = sha512 sha512t256 skein256 skein512 skein1024 + +# This function covers mostly the BSD `cksum`, `sum`, and digest = utilities. It +# also covers the GNU Coreutils `cksum` and `sum`. For the GNU digest = utilities, +# see `_md5sum`. For the `shasum` Perl script, see `_shasum`. +# +# Notes: +# - We really don't do a very good job of handling option exclusivity = here. In +# particular, OpenBSD treats -t and -x as exclusive of each other and = most +# other options =E2=80=94 but there are issues with other variants = too (@todo) +# - Although only OpenBSD's documentation mentions it, -t can be = supplied +# multiple times with all variants to run additional rounds of = testing +# - All digest variants on a given platform share code, but not all = variants are +# found on all platforms (e.g., Darwin only has `md5`). Some BSDs are = actively +# purging legacy/insecure digest tools +# - The documentation for Dragonfly/FreeBSD `sum` says that it's = 'identical to' +# `cksum`, but, as the synopsis confirms, it doesn't take any options +# - FreeBSD's -c is never useful, and Dragonfly's -b/-e are *almost* = never +# useful, with multiple input files +# - NetBSD's -n isn't useful with `sum` and `cksum` unless a digest is = specified +# with -a. Similarly, OpenBSD's -b isn't useful with `cksum` without = -a +# - OpenBSD's -a option allows you to add a b/x suffix to each = algorithm name; +# we don't handle that. Also, only one -a option can be used in = conjunction +# with -c; we don't handle that either + +local -a args + +_pick_variant gnu=3D'Free Soft' unix --version && { + args=3D( + '*: :_files' + '(: -)--help[display help information]' + '(: -)--version[display version information]' + ) + [[ $service =3D=3D *cksum* ]] || args+=3D( + '(-s --sysv)-r[use BSD algorithm (1 KiB blocks)]' + '(-r -s --sysv)'{-s,--sysv}'[use System V algorithm (512 B = blocks)]' + ) + _arguments -s -S : $args + return +} + +[[ $OSTYPE =3D=3D (darwin|dragonfly|freebsd|openbsd)* && $service =3D=3D = sum ]] && { + _default + return +} + +[[ $OSTYPE =3D=3D (darwin|dragonfly|freebsd)* && $service =3D=3D cksum = ]] && { + _arguments -s -S -A '-*' \ + '-o[use specified historic algorithm]:historic algorithm:(1 2 3)' \ + '*: :_files' + return +} + +case $OSTYPE in + darwin*|dragonfly*|freebsd*|netbsd*) + args+=3D( + '(-n -p -r)-q[output checksums only]' + ) + ;| # MATCH AGAIN + darwin*|dragonfly*|freebsd*|openbsd*) + args+=3D( + '(-p -q)-r[reverse output format]' + ) + ;| # MATCH AGAIN + netbsd*|openbsd*) + args+=3D( + '-c[verify checksums from input files]' + ) + ;| # MATCH AGAIN + dragonfly*) + args+=3D( + '-b+[begin processing files at specified offset]:begin offset = (bytes)' + '-e+[end processing files at specified offset]:end offset = (bytes)' + ) + ;; + freebsd*) + args+=3D( + '-c+[verify input against specified digest string]:digest string' + ) + ;; + netbsd*) + args+=3D( + '(-p -q)-n[reverse output format]' + '(-p)-w[warn on malformed checksum files]' + ) + [[ $service =3D=3D (|ck)sum ]] && args+=3D( + '(-o)-a+[use specified algorithm]:algorithm:(crc md2 md4 md5 old1 = old2 rmd160 sha1 sha256 sha384 sha512)' + '(-a)-o+[use specified historic algorithm]:historic algorithm:(1 = 2)' + ) + ;; + openbsd*) + args+=3D( + '-b[output in base64]' + '(-h)-C+[verify input files against checksums in specifed = file]:checksum file:_files' + '(-C)-h+[output checksums to specified file]:checksum = file:_files' + '(-n -r)-q[output checksum only, or suppress check success = messages]' + ) + [[ $service =3D=3D cksum ]] && args+=3D( + '*-a+[use specified algorithm(s)]:algorithm:_values -s , = algorithm cksum md5 rmd160 sha1 sha224 sha256 sha384 sha512/256 sha512' + ) + ;; +esac + +args+=3D( + '-p[output stdin along with checksum]' + '*-s+[checksum specified string]:string' + '*-t[run built-in time trial(s)]' + '-x[run built-in tests]' + '*: :_files' +) + +_arguments -s -S -A '-*' : $args diff --git a/Completion/Unix/Command/_md5sum = b/Completion/Unix/Command/_md5sum index 073e6beba..861b9d135 100644 --- a/Completion/Unix/Command/_md5sum +++ b/Completion/Unix/Command/_md5sum @@ -1,15 +1,48 @@ -#compdef md5sum gmd5sum - -_arguments -S \ - '(-b --binary)'{-b,--binary}'[read in binary mode]' \ - '(-c --check)'{-c,--check}'[read MD5 sums from the FILEs and check = them]' \ - '--tag[create a BSD-style checksum]' \ - '(-t --text)'{-t,--text}'[read in text mode]' \ - "--ignore-missing[don't fail or report status for missing files]" \ - '(-q --quiet)'{-q,--quiet}"[don't print OK for each successfully = verified file]" \ - '--status[no output, status code shows success]' \ - '--strict[exit non-zero for improperly formatted checksum lines]' \ - '(-w --warn)'{-w,--warn}'[warn about improperly formatted checksum = lines]' \ - '(-)--help[display help and exit]' \ - '(-)--version[output version information and exit]' \ - '*:files:_files' +#compdef md5sum gmd5sum b2sum gb2sum sha1sum gsha1sum sha224sum = gsha224sum sha256sum gsha256sum sha384sum gsha384sum sha512sum = gsha512sum + +# This function covers the various digest utilities (which are all = essentially +# the same program) from GNU Coreutils. It does NOT cover GNU `cksum` = and `sum`, +# nor the various BSD digest utilities like `md5` and `sha1` =E2=80=94 = see `_cksum` for +# all of those. See `_shasum` for the `shasum` Perl script. +# +# @todo Support BusyBox? + +local type +local -a args + +case $service in + *md5*) type=3DMD5 ;; + *b2*) type=3DBLAKE2 ;; + *sha*) type=3DSHA${service//[^0-9]/} ;; +esac + +# General options +args+=3D( + '(: -)--help[display help information]' + '(: -)--version[display version information]' +) +# Summing options +args+=3D( + + sum + '(chk)--tag[create BSD-style checksums]' + '(chk -b -t --binary --text)'{-b,--binary}'[read in binary mode]' + '(chk -b -t --binary --text)'{-t,--text}'[read in text mode]' +) +# This is the only option that differs amongst all of these tools +[[ $service =3D=3D *b2* ]] && args+=3D( + '(chk -l --length)'{-l+,--length=3D}'[specify digest length]:digest = length (bits, multiples of 8)' +) +# Verification options +args+=3D( + + chk + '(sum -c --check)'{-c,--check}"[verify $type checksums from input = files]" + "(sum)--ignore-missing[don't fail or report status for missing = files]" + "(sum)--quiet[don't print OK for each verified file]" + '(sum -w --warn)--status[suppress all output]' + '(sum)--strict[exit non-zero for improperly formatted checksum = lines]' + '(sum -w --status --warn)'{-w,--warn}'[warn about each improperly = formatted checksum line]' +) +# Operands +args+=3D( '*: :_files' ) + +_arguments -s -S : $args