From 3efacdbacf88a84160589e612fdbbdc5dda74bf2 Mon Sep 17 00:00:00 2001 From: dana Date: Wed, 27 Feb 2019 19:31:55 -0600 Subject: 44087: _getconf: Complete options, config variables on more systems --- Completion/Unix/Command/_getconf | 107 ++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 29 deletions(-) (limited to 'Completion/Unix/Command/_getconf') 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 -local expl ret=1 +local variant list_cmd ret=1 +local -a context expl line state state_descr args +local -A opt_args local -a syskeys posixkeys confkeys pathkeys1 pathkeys2 allkeys mykeys restkeys syskeys=(ARG_MAX BC_BASE_MAX BC_DIM_MAX BC_SCALE_MAX @@ -23,38 +25,85 @@ pathkeys1=(PIPE_BUF _POSIX_CHOWN_RESTRICTED pathkeys2=(LINK_MAX MAX_CANON MAX_INPUT NAME_MAX PATH_MAX PIPE_BUF) mykeys=($syskeys $posixkeys $confkeys $pathkeys1 $pathkeys2) -if [[ CURRENT -eq 2 ]]; then - _tags syswideconfig pathconfig standardsconfig confstring restconfig +if _pick_variant -r variant gnu='(Free Soft|GLIBC)' $OSTYPE --version; then + # GNU getconf doesn't use getopt(3), strangely + args+=( + '(: * -)--help[display help information]' + '(: * -)--version[display version information]' + '(1 -)-a[display all configuration variables and their values]' + '(-)-v[specify programming environment]: :->env' + ) + : ${list_cmd:='$words[1] -a'} - allkeys=(${${(f)"$(getconf -a 2>/dev/null)"}%%[: ]*}) - restkeys=(${allkeys:|mykeys}) +else + [[ $variant == (netbsd*|solaris*) ]] && { + args+=( '(1 -)-a[display all configuration variables and their values]' ) + : ${list_cmd:='$words[1] -a'} + } - while _tags; do - _requested -V syswideconfig expl 'systemwide configuration variables' \ - compadd -S '' $syskeys && ret=0 + [[ $variant == openbsd* ]] && { + args+=( + '(: - *)-l[display all system (non-path) configuration variables]' + '(: - *)-L[display all path configuration variables]' + ) + : ${list_cmd:='$words[1] -l; $words[1] -L'} + } - _requested -V standardsconfig \ - expl 'system-standards configuration variables' \ - compadd -S '' $posixkeys && ret=0 + [[ $variant == netbsd* ]] || + args+=( '(-)-v+[specify programming environment]: :->env' ) - _requested -V confstring \ - expl 'configuration-dependent string variables' \ - compadd -S '' $confkeys && ret=0 + # This is a bit silly, but actually pretty accurate, where available + : ${list_cmd:=' + command strings -- ${${(Q)words[1]}:c} | + LC_ALL=C GREP_OPTIONS= command grep -xE \ + "_*[A-Z][A-Z0-9_]*_[A-Z0-9_]*|NZERO|PATH|[A-Z]+(BITS|SIZE)" + '} +fi - _requested pathconfig && - while _next_label -V pathconfig expl 'system path configuration variables'; do - compadd "$expl[@]" -S '' $pathkeys1 && ret=0 - compadd "$expl[@]" -S ' ' $pathkeys2 && ret=0 - done +_arguments -S -A '-*' : $args '1: :->var' '2: :_files' && ret=0 - if (( ${#restkeys} )); then - _requested -V restconfig \ - expl 'remaining unclassified configuration variables' \ - compadd -S '' $restkeys && ret=0 - 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=0 + ;; + var) + _tags syswideconfig pathconfig standardsconfig confstring restconfig - (( ret )) || return 0 - done -else - _files -/ -fi + allkeys=(${${(f)"$( _call_program variables $list_cmd )"}%%[=:[:space:]]*}) + restkeys=(${allkeys:|mykeys}) + + while _tags; do + _requested -V syswideconfig expl 'system-wide configuration variable' \ + compadd -S '' $syskeys && ret=0 + + _requested -V standardsconfig \ + expl 'system-standards configuration variable' \ + compadd -S '' $posixkeys && ret=0 + + _requested -V confstring \ + expl 'configuration-dependent string variable' \ + compadd -S '' $confkeys && ret=0 + + _requested pathconfig && + while _next_label -V pathconfig expl 'system path configuration variable'; do + compadd "$expl[@]" -S '' $pathkeys1 && ret=0 + compadd "$expl[@]" -S ' ' $pathkeys2 && ret=0 + done + + if (( ${#restkeys} )); then + _requested -V restconfig \ + expl 'remaining unclassified configuration variable' \ + compadd -S '' $restkeys && ret=0 + fi + + (( ret )) || break + done + ;; +esac + +return ret -- cgit 1.4.1