From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5115 invoked from network); 4 May 2001 17:19:14 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 4 May 2001 17:19:14 -0000 Received: (qmail 27579 invoked by alias); 4 May 2001 17:19:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 14225 Received: (qmail 27568 invoked from network); 4 May 2001 17:19:09 -0000 X-VirusChecked: Checked Sender: kiddleo@cav.logica.co.uk Message-ID: <3AF2E46F.AB08FFB8@u.genie.co.uk> Date: Fri, 04 May 2001 18:18:39 +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: chown completion Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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