From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id e8e1b03d for ; Tue, 26 Feb 2019 20:36:40 +0000 (UTC) Received: (qmail 28289 invoked by alias); 26 Feb 2019 20:36:21 -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: 44087 Received: (qmail 24622 invoked by uid 1010); 26 Feb 2019 20:36:21 -0000 X-Qmail-Scanner-Diagnostics: from mail-it1-f193.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25370. spamassassin: 3.4.2. Clear:RC:0(209.85.166.193):SA:0(-1.9/5.0):. Processed in 3.301374 secs); 26 Feb 2019 20:36:21 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.193 as permitted sender) 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=fq8wfhiB4pUWt4nrBvp9iy7IxrLcu9xAQT8MCRSX9KY=; b=hND5prf8lnyPv+pimI1KXQ4pHyHLn8iKsKE5Vr9JAZWX93nWfxIQQk9n/jQMXJRqMy EVw8+EIVm4TX/f183C9DxNOkhgsyYaJeBTzw1ackvMI+20lqlC1FVF3EQlVv1gFZUXKN i6OCnEeYudGDNH23v0Fd+ku9AAbnM7KPcxUvPxDXOz7eTch8s2puAfWhTh5cBZfiTkHH DyfOAfHiGMwPmoH0AGYZXz0XkuSPbHhadjNE/GLJ0xLPYx6pIiW2CcA6WOJAKzpn8U6w gcf/kkSGHUFqhAIprLPg2DIGlcSuJKc/5afayk9AciOfGasEC2e4s/tc6em6BcAcIyRV NstA== 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=fq8wfhiB4pUWt4nrBvp9iy7IxrLcu9xAQT8MCRSX9KY=; b=eOow3gf+kVeiiK0zY1mQa6yqJ9Ortc5JMI8tRPpsxykHw798htcBEdtAQqj2X8vb4x WlYHq8ljXYvTbGzMzHjno/g6BSxzhKZJi36JwO2Aub76lSYvQxx6KWxdPIFzlaTeHCOK r6+7Xhva53+Jv2/WWB/hdfotQRQhLZJ4psU5eYh9aY3fw+yOSHxVKcdCVjT0oslthUBr AvT4vP4TJNJB03aS1L28WL93c5wh6z455XUvYiDpYCHQC8zr6NQDqiqQVCuBmG8WErVJ V2Kihw6Jw5svdquMA5Z0YfZnzd/QSpJu3XM3Zc5qPsLXAM++3vUBmVHCJ2Eew/bk9ttj aP7Q== X-Gm-Message-State: AHQUAuY7R6zbWtqQf0FJ3eV/UkbDfJTb/+gt/W0VgVaxY0tkZj+nXzNO U4lsseRahj7OoZ4bYi3ufSvsZgt4Jji3qw== X-Google-Smtp-Source: AHgI3IZ0r3bfdoADJ7JQvUkh8DdMItmZK84nTe65x2Lm9ArL8xPgGf0EazhSzFAwMe0TP2raT9nxZQ== X-Received: by 2002:a02:9898:: with SMTP id q24mr13279738jaj.135.1551213342364; Tue, 26 Feb 2019 12:35:42 -0800 (PST) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: [PATCH] Completion: Improve _getconf Message-Id: Date: Tue, 26 Feb 2019 14:35:40 -0600 To: Zsh hackers list X-Mailer: Apple Mail (2.3445.9.1) * Complete -a, -v, and other options where applicable * Get the full list of config variables even on systems without -a * Don't pluralise descriptions * Don't call _files with -/ (it's not restricted to directories) dana diff --git a/Completion/Unix/Command/_getconf = b/Completion/Unix/Command/_getconf index f2c713a52..36f58226c 100644 --- a/Completion/Unix/Command/_getconf +++ b/Completion/Unix/Command/_getconf @@ -1,6 +1,8 @@ #compdef getconf =20 -local expl ret=3D1 +local variant list_cmd ret=3D1 +local -a context expl line state state_descr args +local -A opt_args =20 local -a syskeys posixkeys confkeys pathkeys1 pathkeys2 allkeys mykeys = restkeys syskeys=3D(ARG_MAX BC_BASE_MAX BC_DIM_MAX BC_SCALE_MAX @@ -23,38 +25,85 @@ pathkeys1=3D(PIPE_BUF _POSIX_CHOWN_RESTRICTED pathkeys2=3D(LINK_MAX MAX_CANON MAX_INPUT NAME_MAX PATH_MAX PIPE_BUF) mykeys=3D($syskeys $posixkeys $confkeys $pathkeys1 $pathkeys2) =20 -if [[ CURRENT -eq 2 ]]; then - _tags syswideconfig pathconfig standardsconfig confstring restconfig +if _pick_variant -r variant gnu=3D'(Free Soft|GLIBC)' $OSTYPE = --version; then + # GNU getconf doesn't use getopt(3), strangely + args+=3D( + '(: * -)--help[display help information]' + '(: * -)--version[display version information]' + '(1 -)-a[display all configuration variables and their values]' + '(-)-v[specify programming environment]: :->env' + ) + : ${list_cmd:=3D'$words[1] -a'} =20 - allkeys=3D(${${(f)"$(getconf -a 2>/dev/null)"}%%[: ]*}) - restkeys=3D(${allkeys:|mykeys}) +else + [[ $variant =3D=3D (netbsd*|solaris*) ]] && { + args+=3D( '(1 -)-a[display all configuration variables and their = values]' ) + : ${list_cmd:=3D'$words[1] -a'} + } =20 - while _tags; do - _requested -V syswideconfig expl 'systemwide configuration = variables' \ - compadd -S '' $syskeys && ret=3D0 + [[ $variant =3D=3D openbsd* ]] && { + args+=3D( + '(: - *)-l[display all system (non-path) configuration = variables]' + '(: - *)-L[display all path configuration variables]' + ) + : ${list_cmd:=3D'$words[1] -l; $words[1] -L'} + } =20 - _requested -V standardsconfig \ - expl 'system-standards configuration variables' \ - compadd -S '' $posixkeys && ret=3D0 + [[ $variant =3D=3D netbsd* ]] || + args+=3D( '(-)-v+[specify programming environment]: :->env' ) =20 - _requested -V confstring \ - expl 'configuration-dependent string variables' \ - compadd -S '' $confkeys && ret=3D0 + # This is a bit silly, but actually pretty accurate, where available + : ${list_cmd:=3D' + command strings -- ${${(Q)words[1]}:c} | + LC_ALL=3DC GREP_OPTIONS=3D command grep -xE \ + "_*[A-Z][A-Z0-9_]*_[A-Z0-9_]*|NZERO|PATH|[A-Z]+(BITS|SIZE)" + '} +fi =20 - _requested pathconfig && - while _next_label -V pathconfig expl 'system path configuration = variables'; do - compadd "$expl[@]" -S '' $pathkeys1 && ret=3D0 - compadd "$expl[@]" -S ' ' $pathkeys2 && ret=3D0 - done +_arguments -S -A '-*' : $args '1: :->var' '2: :_files' && ret=3D0 =20 - if (( ${#restkeys} )); then - _requested -V restconfig \ - expl 'remaining unclassified configuration variables' \ - compadd -S '' $restkeys && ret=3D0 - fi +case $state in + env) + _wanted environments expl 'programming environment' compadd - \ + POSIX_V{6,7}_ILP32_OFF32 \ + POSIX_V{6,7}_ILP32_OFFBIG \ + POSIX_V{6,7}_LP64_OFF64 \ + POSIX_V{6,7}_LPBIG_OFFBIG \ + && ret=3D0 + ;; + var) + _tags syswideconfig pathconfig standardsconfig confstring = restconfig =20 - (( ret )) || return 0 - done -else - _files -/ -fi + allkeys=3D(${${(f)"$( _call_program variables $list_cmd = )"}%%[=3D:[:space:]]*}) + restkeys=3D(${allkeys:|mykeys}) + + while _tags; do + _requested -V syswideconfig expl 'system-wide configuration = variable' \ + compadd -S '' $syskeys && ret=3D0 + + _requested -V standardsconfig \ + expl 'system-standards configuration variable' \ + compadd -S '' $posixkeys && ret=3D0 + + _requested -V confstring \ + expl 'configuration-dependent string variable' \ + compadd -S '' $confkeys && ret=3D0 + + _requested pathconfig && + while _next_label -V pathconfig expl 'system path configuration = variable'; do + compadd "$expl[@]" -S '' $pathkeys1 && ret=3D0 + compadd "$expl[@]" -S ' ' $pathkeys2 && ret=3D0 + done + + if (( ${#restkeys} )); then + _requested -V restconfig \ + expl 'remaining unclassified configuration variable' \ + compadd -S '' $restkeys && ret=3D0 + fi + + (( ret )) || break + done + ;; +esac + +return ret