zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: complete BSD login classes and update for env
Date: Sat, 06 Feb 2021 00:18:56 +0100	[thread overview]
Message-ID: <99873-1612567136.389140@kGW-.11wP.7Egj> (raw)

I updated the options in the env completion for newer FreeBSD and
Dragonfly. After handling the login classes, it occurred to me that we
could probably use that elsewhere. A quick search turned up pgrep, su
and useradd/mod so I've factored that out into its own function.

Oliver

diff --git a/Completion/Unix/Command/_env b/Completion/Unix/Command/_env
index 27978d936..a5dd49d37 100644
--- a/Completion/Unix/Command/_env
+++ b/Completion/Unix/Command/_env
@@ -1,6 +1,7 @@
 #compdef env genv
 
-local context state line variant args ign ret=1
+local context state line variant ign ret=1
+local -a args suf
 
 _pick_variant -r variant gnu=Free\ Soft $OSTYPE --version
 case $variant in
@@ -20,8 +21,15 @@ case $variant in
       "${ign}(- *)--version[display version information]"
     )
   ;;
-  freebsd*|darwin*)
+  freebsd*)
     args=(
+      '-0[use NUL, not newline after each variable in output]'
+      '-L[add variables from system login.conf(5)]: :->user-class'
+      '-U[add variables from user and system login.conf(5)]: :->user-class'
+    )
+  ;|
+  freebsd*|darwin*|dragonfly*)
+    args+=(
       '(-i)*-u+[remove variable from the environment]:env var to remove:_parameters -g "*export*"'
       '-P+[specify alternate executable search PATH]:path:_dir_list'
       '-S+[perform word splitting]:string to split'
@@ -44,11 +52,23 @@ _arguments $args \
   '*::arguments:->normal' && ret=0
 
 if [[ -n $state ]]; then
-  while [[ $words[1] = *=* ]]; do
-    shift words
-    (( CURRENT-- ))
-  done
-  _normal && ret=0
+  case $state in
+    normal)
+      while [[ $words[1] = *=* ]]; do
+        shift words
+        (( CURRENT-- ))
+      done
+      _normal && ret=0
+    ;;
+    user-class)
+      if compset -P 1 '*/'; then
+        _login_classes && ret=0
+      else
+        compset -S '/*' || suf=( -qS/ )
+        _users $suf && ret=0
+      fi
+    ;;
+  esac
 fi
 
 return ret
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index 3f00b21dc..49184307f 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -5,7 +5,6 @@
 #   (which changed the behaviour of -f and added -a)
 # - We don't really need to keep pgopts and pkopts separate, but it seems like
 #   it should make things a bit easier to follow
-# - @todo We could complete log-in classes given to -c
 # - @todo We could complete routing tables given to -T
 
 local curcontext="$curcontext" state line ret=1 expl pgopts pkopts no
@@ -18,7 +17,7 @@ typeset -a arguments sig_arguments aopts
 # overridden below
 arguments=(
   '-a[include process ancestors in match list]'
-  '-c+[match only on specified login class]:login class'
+  '-c+[match only on specified login class]:login class:_login_classes'
   '(-F --pidfile)'{-F+,--pidfile=}'[match only processes in specified PID file]:PID file:_files'
   '(-f --full)'{-f,--full}'[match against full command line]'
   '(-G --group)'{-G+,--group=}'[match only on specified real group IDs]: :_sequence _groups'
diff --git a/Completion/Unix/Command/_su b/Completion/Unix/Command/_su
index 066f5c3b6..1af751a17 100644
--- a/Completion/Unix/Command/_su
+++ b/Completion/Unix/Command/_su
@@ -35,7 +35,7 @@ case $OSTYPE in
   ;|
   *bsd*|dragonfly*)
     args+=(
-      '-c+[use settings from specified login class]:class'
+      '-c+[use settings from specified login class]:class:_login_classes'
     )
   ;|
   freebsd*) args+=( '-s[set the MAC label]' ) ;;
diff --git a/Completion/Unix/Command/_user_admin b/Completion/Unix/Command/_user_admin
index c7e1efc80..db1c977ad 100644
--- a/Completion/Unix/Command/_user_admin
+++ b/Completion/Unix/Command/_user_admin
@@ -54,7 +54,7 @@ case ${service%???}:${(M)service%???}:$OSTYPE in
   ;|
   user:*:(net|open)bsd*)
     args+=(
-      '-L[specify login class]:login class'
+      '-L[specify login class]:login class:_login_classes'
       '-p+[specify encrypted password]:encrypted password'
     )
   ;|


                 reply	other threads:[~2021-02-05 23:19 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=99873-1612567136.389140@kGW-.11wP.7Egj \
    --to=opk@zsh.org \
    --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).