From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16537 invoked by alias); 18 Jun 2018 23:24:31 -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: 43060 Received: (qmail 20688 invoked by uid 1010); 18 Jun 2018 23:24:31 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f65.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.65):SA:0(-1.9/5.0):. Processed in 1.469133 secs); 18 Jun 2018 23:24:31 -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=R88QyREwcoPqGGYD+1PZdVry+Sj5PA31AOCPheLptyk=; b=tDm0/vLKvo9JMgM838cFN1qFY7Otf23nax3kPpmsmIN2W28o6OOq2Zgpvmv6Li2GZB PUmqt2AFgZs463tqam7Qy1sHoha/pjcaaeILsSSu1qgI56afwop1kg1WJt7vzYtJmhAJ XmIjxdlNVCowiBIJw0+XMQaskQhYqcE2zudXaLqQmxvvit9pZBOwCsaDJZF2tSjIuTAb 3zB1KJKl0Y6QgG/D1iB885ODRQdfx50AEmQ0TPbQ7uxdDXOJ5IAtW7i2ufOiVFq1LA5K Bjrd2oCJTT3oZrIXmZl9xZ0FqHrNhSkaH9H7kgWxSLlpOo7NewqBn0xdgEgeHXRUudCB goog== 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=R88QyREwcoPqGGYD+1PZdVry+Sj5PA31AOCPheLptyk=; b=IIhMQBVfsPc+yeHhC5eY/9WQg2HfKA40WIb7MPjMUt1xjT+vL7e1KyCL0AezJNTjzI L4j3cyTrg48gaagKzc4c6Zo4sQtmtUxF5+nqLQvFOmNF+54qr1yzBDwq79EiXvZ/WSCM g1dddlUMOx4/GqTnskt97RnxU+vPKGLjfS0szCFtvzOnWH3A8rX6xCHJO+Xy7BXZC+Nv ALBLu3kLLlqPTlrEMWLkaPeR7fzYGPwFubbiwrlbdh0bsKRLA+EnKCTKQnxngtJOuxPF 0KG7/8sRTTEAVAf6C+Tn3BDmiBRicRaRrS5SdGblTJf8/OhHAQsPBOW29eUroWWlp32I xP+g== X-Gm-Message-State: APt69E2qHWCgs60F99fjGmcoayJcJF2xX2zGPYtovt0hAyv+5WkS0KRp bLQTiYk3tKZLfw4JZDeG6v2Ck0a0Jmk= X-Google-Smtp-Source: ADUXVKKIkl6DDOfU0kCsi4RdROey44uEu5skIJQGpnPhRe5CKAsnvZZBt19uTKxyVz+A6fYl9/81pg== X-Received: by 2002:a02:666a:: with SMTP id l42-v6mr12013120jaf.70.1529364265898; Mon, 18 Jun 2018 16:24:25 -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: Improve _stat Message-Id: <9EA02E08-4180-4310-BBBC-2D4F31B0BD98@dana.is> Date: Mon, 18 Jun 2018 18:24:24 -0500 To: Zsh workers X-Mailer: Apple Mail (2.3445.6.18) This rounds out completion for stat: * Add support for GNU and *BSD/Darwin variants (Solaris seems to use = GNU) * Use a (hopefully) more accurate method of differentiating the zsh = built-in from the external tools. I don't believe that _builtin actually = updates the precommands array, so that check is a bit superfluous right now, but = it seems like a logical change to make in the future * Move from Zsh/Command to Unix/Command to reflect its broadened purpose I've held off on completing -c/-f format strings for now; hopefully will = get around to it eventually though. dana diff --git a/Completion/Unix/Command/_stat = b/Completion/Unix/Command/_stat new file mode 100644 index 000000000..2e84d6bf0 --- /dev/null +++ b/Completion/Unix/Command/_stat @@ -0,0 +1,96 @@ +#compdef stat gstat zstat + +# Notes: +# - @todo It would be nice to complete the -c/-f format strings some = day +# - @todo It should be possible to complete NFS file handles on FreeBSD = and +# Dragonfly by parsing the output of `lsof -N`, but it's not = available by +# default =E2=80=94 is there another way? + +local expl variant precmd ret=3D1 +local -a context line state state_descr args aopts=3D( -A '-*' ) +local -A opt_args + +if [[ $service =3D=3D zstat ]] || [[ $precommands[-1] =3D=3D builtin = ]]; then + variant=3Dzsh +else + [[ $precommands[-1] =3D=3D command ]] && precmd=3Dcommand + _pick_variant -c "${precmd:+$precmd }${words[1]}" -r variant \ + gnu=3D'Free Soft' zsh=3D'no files given' unix --version +fi + +case $OSTYPE-$variant in + *-zsh) + args=3D( + "(-H)-A[assign the results to array, don't print]:array = variable:_parameters -g '*array*'" + - set1 + +device +inode +mode +nlink +uid +gid +rdev + +size +atime +mtime +ctime +blksize +block +link + "(-A)-H[assign the results to associative array, don't = print]:associative array variable:_parameters -g '*association*'" + '(:)-f[stat the specified file descriptor]:file = descriptor:_file_descriptors' + '(-s)-F[specify strftime(3) format string]: :_date_formats zsh' + '(-s)-g[show times in GMT/UTC]' + # Note that this has the *opposite* effect of other variants' -L = option! + "-L[don't dereference symbolic links; use lstat(2)]" + '(-N)-n[always show names of files]' + '(-n)-N[never show names of files]' + '-o[print file modes in octal rather than decimal]' + '-r[print raw data]' + '-s[print mode, UID, GID, and times as strings]' + '(-T)-t[always show type names]' + '(-t)-T[never show type names]' + '*: :_files' + - set2 + '-l[list stat types]' + ) + ;; + *-gnu) + aopts=3D( ) + args=3D( + '*: :_files' + '(: * -)--help[display help information]' + '(: * -)--version[display version information]' + '(-L --dereference)'{-L,--dereference}'[dereference symbolic = links]' + + '(d)' # Display options + {-c+,--format=3D}'[display per the specified format = string]:format string' + {-f,--file-system}'[display file-system status instead of file = status]' + '--printf=3D[display as with -c, but interpret backslash escapes = like printf(3)]' + {-t,--terse}'[display in terse format]' + ) + ;; + darwin*|dragonfly*|*bsd*) + args=3D( + '*: :->files-or-handles' + '(-H)-L[dereference symbolic links]' + '-q[suppress error messages about lstat(2)/stat(2) failure]' + + '(d)' # Primary display options + '(-F)-f+[display per the specified format string]:format string' + '-l[display in `ls -lT` format]' + '(-F -t)-r[display in raw (numerical) format]' + '(-F -t)-s[display in shell variable-assignment format]' + '(-F)-x[display in verbose (Linux-style) format]' + + D # Secondary display options + '(-f -r -s -x)-F[append file type indicators (implies -l)]' + '-n[suppress terminating newlines]' + '(-r -s)-t+[specify strftime(3) format string]: :_date_formats' + ) + ;| # MATCH AGAIN + dragonfly*|freebsd*) + args+=3D( + + df + '(-L)-H[treat arguments as hexadecimal-formatted NFS file = handles]' + ) + ;; +esac + +(( $#args )) || args=3D( '*: :_files' ) + +_arguments -s -S $aopts : $args && ret=3D0 + +[[ $state =3D=3D files-or-handles ]] && +if [[ -n ${opt_args[(i)*--H]} ]]; then + _message -e nfs-handles 'NFS file handle' +else + _files && ret=3D0 +fi + +return ret diff --git a/Completion/Zsh/Command/_stat b/Completion/Zsh/Command/_stat deleted file mode 100644 index 73bbef471..000000000 --- a/Completion/Zsh/Command/_stat +++ /dev/null @@ -1,33 +0,0 @@ -#compdef stat zstat - -local expl ret=3D1 - -if [[ $service =3D=3D zstat ]] || - (( ${+builtins[stat]} )) ||=20 - { (( ! ${+builtins} )) && [[ $(type -w stat) =3D=3D '*: builtin' = ]] } -then - _arguments -s -S : \ - '(-H)-A[assign the results to array, don'\''t print]:array = variable:_parameters -g "*array*"' \ - - set1 \ - +device +inode +mode +nlink +uid +gid +rdev \ - +size +atime +mtime +ctime +blksize +block +link \ - '(-A)-H[assign the results to associative array, don'\''t = print]:associative array variable:_parameters -g "*association*"' \ - '(:)-f[stat a file descriptor]:file descriptor:_file_descriptors' \ - '(-s)-F:strftime(3) format string:_date_formats zsh' \ - '(-s)-g[show times in GMT/UTC]' \ - '-L[don'\''t dereference symbolic links; use lstat(2)]' \ - '(-N)-n[always show names of files]' \ - '(-n)-N[never show names of files]' \ - '-o[print file modes in octal rather than decimal]' \ - '-r[print raw data]' \ - '-s[print mode,uid,gid and times as strings]' \ - '(-T)-t[always show type names]' \ - '(-t)-T[never show type names]' \ - '*:files to stat:_files' \ - - set2 \ - '-l[list stat types]' -else - # TODO: system-specific completion - # TODO: choose this codepath if 'command stat ...' or '=3Dstat ...' = is used - _files -fi