zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@u.genie.co.uk>
To: zsh-workers@sunsite.dk
Subject: chown completion
Date: Fri, 04 May 2001 18:18:39 +0100	[thread overview]
Message-ID: <3AF2E46F.AB08FFB8@u.genie.co.uk> (raw)

Below is a patch against _chown which I've not committed. It adds a
certain amount of intelligence to reduce the number of matches. It
restricts the files matched to just those for which the chown command
would make sense, i.e. excluding those for which the ownership would be
unchanged by the chown command. I've got a few questions though before
I either finish or abandon this.

How could I avoid the two consecutive _files calls to specify files
where either the user is not $usr or the group is not $grp?
*(^u.$usr.g.$grp.) matches files where user is not $usr AND group is
not $grp.

For non-root users, only the groups listed by the groups command are
completed first. I think that it is only some configurations which have
this restriction on chown. Does anyone have any ideas on how to detect
this? Does the groups command work the same on other unices?

It could also restrict files to those owned by the current user (unless
it is root) as you can't chown other people's files.

Any ideas on how it should deal with invalid users or groups? As it is,
it displays `_path_files:330: unknown user' which isn't too bad really.
This also doesn't currently handle users and groups being specified
numerically but that should be fairly easy to do.

Incidentally, if I separate the user/groups with a colon, not a dot in
the glob, I get this message:
    _path_files:330: bad pattern: *(^g:users

Oliver

--- _chown      Mon Apr  2 12:46:20 2001
+++ _chown      Fri May  4 17:42:47 2001
@@ -1,10 +1,13 @@
 #compdef chown chgrp
 
-local suf
+local suf usr grp expl ret=1
 
 if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
   if [[ $service = chgrp ]] || compset -P '*[:.]'; then
-    _groups
+    if (( GID && $+commands[groups] )); then
+      _wanted groups expl 'group' compadd $(groups) && return 0
+    fi
+    _groups && return 0
   else
     if [[ $OSTYPE = (solaris*|hpux*) ]]; then
       suf=':'
@@ -12,8 +15,21 @@
       suf='.'
     fi
     compset -S '.*' && unset suf
-    _users -S "$suf" -q
+    _users -S "$suf" -q && return 0
   fi
 else
-  _files
+  usr=${words[CURRENT-1]%%[.:]*}
+  grp=${words[CURRENT-1]#*[.:]}
+
+  if [[ $service = chgrp ]]; then
+    _files -g "*(^g.$grp.)" && return 0
+  elif [[ $usr = $grp ]]; then
+    _files -g "*(^u.$usr.)" && return 0
+  else
+    _files -g "*(^u.$usr.)" && ret=0
+    _files -g "*(^g.$grp.)" && ret=0
+  fi
+  _files && ret=0
 fi
+
+return ret

_____________________________________________________________________
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp


             reply	other threads:[~2001-05-04 17:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-04 17:18 Oliver Kiddle [this message]
2001-05-04 22:15 ` Bart Schaefer
2001-05-07  9:17 ` Sven Wischnowsky

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=3AF2E46F.AB08FFB8@u.genie.co.uk \
    --to=opk@u.genie.co.uk \
    --cc=zsh-workers@sunsite.dk \
    /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).