Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: chown completion
- X-seq: zsh-workers 14282
- From: Oliver Kiddle <opk@xxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: Re: chown completion
- Date: Wed, 09 May 2001 16:20:48 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Sender: kiddleo
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author