From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9229 invoked from network); 9 May 2001 15:21:07 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 9 May 2001 15:21:07 -0000 Received: (qmail 26480 invoked by alias); 9 May 2001 15:20:58 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 14282 Received: (qmail 26456 invoked from network); 9 May 2001 15:20:58 -0000 Sender: kiddleo Message-ID: <3AF9604F.F342D1D0@u.genie.co.uk> Date: Wed, 09 May 2001 16:20:48 +0100 From: Oliver Kiddle X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.15 i686) X-Accept-Language: en MIME-Version: 1.0 To: zsh-workers@sunsite.dk Subject: PATCH: Re: chown completion Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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