From: dana <dana@dana.is>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Completion: Improve _getconf
Date: Tue, 26 Feb 2019 14:35:40 -0600 [thread overview]
Message-ID: <DC33CEE0-CE77-4FD5-9A4F-CE9EE33D2B43@dana.is> (raw)
* 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
-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
reply other threads:[~2019-02-26 20:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DC33CEE0-CE77-4FD5-9A4F-CE9EE33D2B43@dana.is \
--to=dana@dana.is \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).