zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@u.genie.co.uk>
To: zsh-workers@sunsite.dk
Subject: PATCH: Re: chown completion
Date: Wed, 09 May 2001 16:20:48 +0100	[thread overview]
Message-ID: <3AF9604F.F342D1D0@u.genie.co.uk> (raw)

Thanks for the various answers to my questions on this.

I wrote:
> 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?

I checked this out in the IRIX documentation and it is configured with
a kernel parameter that you can only read as root with an IRIX specific
command. Interestingly, it claims that the two behaviours are a
BSD/SYSV difference. Anyway, I'm going to leave _chown completing
groups the current user is a member of first because it is probably
useful even if you can chgrp files to anything. We can always use a
style if there are any complaints.

> Does the groups command work the same on other unices?

This seems to be the case but let me know if you find any exceptions.

> 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.

> This also doesn't currently handle users and groups being specified
> numerically but that should be fairly easy to do.

I've done these and fixed handling where chown is used without one of
user/group.

If anyone doesn't like the file restricting, they should be able to get
round it with a file-patterns style.

The only thing which isn't done is checking for non-existant groups but
I don't know a portable way and the handling isn't too bad.

The next thing will be something similar for chmod.

Oliver

Index: Completion/Unix/Command/_chown
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_chown,v
retrieving revision 1.1
diff -u -r1.1 _chown
--- Completion/Unix/Command/_chown      2001/04/02 11:46:20     1.1
+++ Completion/Unix/Command/_chown      2001/05/09 15:13:47
@@ -1,10 +1,13 @@
 #compdef chown chgrp
 
-local suf
+local suf usr grp req expl
 
 if [[ CURRENT -eq 2 || CURRENT -eq 3 && $words[CURRENT-1] = -* ]]; then
   if [[ $service = chgrp ]] || compset -P '*[:.]'; then
-    _groups
+    if (( EGID && $+commands[groups] )); then  # except for root
+      _wanted groups expl 'group' compadd $(groups) && return 0
+    fi
+    _groups && return 0
   else
     if [[ $OSTYPE = (solaris*|hpux*) ]]; then
       suf=':'
@@ -12,8 +15,19 @@
       suf='.'
     fi
     compset -S '.*' && unset suf
-    _users -S "$suf" -q
+    _users -S "$suf" -q && return 0
   fi
 else
-  _files
+  if [[ $service = chgrp ]]; then
+    grp=${words[CURRENT-1]}
+  else
+    usr=${words[CURRENT-1]%%[.:]*}
+    usr=${${(M)usr:#[0-9]#}:-${userdirs[$usr]:+.$usr.}}
+    grp=${${(M)words[CURRENT-1]%%[.:]*}#?}
+  fi
+  [[ -n $grp ]] && grp="${${(M)grp:#[0-9]#}:-.$grp.}"
+  req=( ${usr:+\^u$usr} ${grp:+\^g$grp} )
+  (( EUID )) && req=( u$EUID$^req )
+
+  _files -g "*(${(j:,:)req})" && return 0
 fi


                 reply	other threads:[~2001-05-09 15:21 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=3AF9604F.F342D1D0@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).