From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11793 invoked from network); 27 Dec 2005 05:51:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 27 Dec 2005 05:51:14 -0000 Received: (qmail 91982 invoked from network); 27 Dec 2005 05:51:06 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 27 Dec 2005 05:51:06 -0000 Received: (qmail 18805 invoked by alias); 27 Dec 2005 05:51:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22110 Received: (qmail 18795 invoked from network); 27 Dec 2005 05:51:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 27 Dec 2005 05:51:01 -0000 Received: (qmail 91766 invoked from network); 27 Dec 2005 05:51:01 -0000 Received: from vms044pub.verizon.net (206.46.252.44) by a.mx.sunsite.dk with SMTP; 27 Dec 2005 05:51:00 -0000 Received: from candle.brasslantern.com ([71.116.81.225]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPA id <0IS500LK56WXAOV2@vms044.mailsrvcs.net> for zsh-workers@sunsite.dk; Mon, 26 Dec 2005 23:50:59 -0600 (CST) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id jBR5ovuq031457 for ; Mon, 26 Dec 2005 21:50:57 -0800 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id jBR5oveK031456 for zsh-workers@sunsite.dk; Mon, 26 Dec 2005 21:50:57 -0800 Date: Tue, 27 Dec 2005 05:50:57 +0000 From: Bart Schaefer Subject: More fun with _su To: zsh-workers@sunsite.dk Message-id: <1051227055057.ZM31455@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii On Dec 27, 12:22am, Bart Schaefer wrote: } } I'm working on improving _su, mainly so that it'll call _normal on the } argument of the -c flag, the way _sh does. So what follows is what I have so far. Fiddling with $first is to address another _arguments problem; completing su someuser -f it fails to recognize that the "first non-option argument", "someuser", is already present on the line, and insists on completing user names again if '1:user name:_users' is seen. It's as if the count of non-option arguments is reset to zero by the interposition of an option argument. There are three other things that still have me stumped: (1) I can't figure out how to tell _arguments that it should omit the -l and --login options when a solitary "-" is already present. Yes, I could hack it, similar to what I did for $shell and $first, but it seems as if it should be possible another way. (2) When calling _dispatch with -default- at the end, which is about the only thing I tried to keep from the previous _su, the listing of file names is sometimes doubled. I traced this as far as discovering that _files is called at least twice, once to populate the "files" group and again to populate the "globbed-files" group, and both get the same list of files -- but why this happens, and why specifically it only appears to happen when completing after some shell paths given with -s (and not when completing after other shell paths or after --shell=...), remains mysterious. I think this is related to the matcher-list problem mentioned in the other thread, but it happens whether or not the matcher-list style is set. (3) When completing after --command=, compset -q insists on removing quotes and adding backslashes instead. This is somewhat annoying. Completing in a separate word, as when after -c, allows the quotes to remain. No point in sending a patch, it's almost entirely rewritten. ------------ #compdef su local -A opt_args local -a args state context local shell=${words[(i)(-s|--shell=*)]} first='1:user name:_users' local usr=root line if _pick_variant gnu="Free Software Foundation" unix --version; then args=( '(--command)-c[pass command to shell]:command string:->command' '(-c)--command=-[pass command to shell]:command string:->command' '-f[pass -f to shell (csh)]' '(--login)-l[use a login shell]' '(-l)--login[use a login shell]' '(-p --preserve-environment)-m[do not reset environment]' '(-m --preserve-environment)-p[do not reset environment]' '(-m -p)--preserve-environment[do not reset environment]' '(--shell)-s[run the specified shell]:shell:->shell' '(-s)--shell=-[run the specified shell]:shell:->shell' ) else args=( '-c[pass command to shell]:command string:->command' '-l[use a login shell]' '-s[run the specified shell]:shell:->shell' ) fi if [[ $#words -ge 2 && $words[2] != -* && CURRENT -ne 2 ]]; then usr=$words[2] first= fi [[ $words[shell] == -s ]] && ((shell++)) if [[ CURRENT -ne shell && -n ${words[shell]} ]]; then shell=${words[shell]#*=} else shell="${${(M@)${(@f)$(rest" && return case $state in (command) compset -q _normal && return ;; (shell) compadd ${(f)^"$(