From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16842 invoked by alias); 23 Aug 2014 19:30:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33046 Received: (qmail 23484 invoked from network); 23 Aug 2014 19:30:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140823123117.ZM23674@torch.brasslantern.com> Date: Sat, 23 Aug 2014 12:31:17 -0700 In-reply-to: <140822210846.ZM22535@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: Bug path completion chsh -s" (Aug 22, 9:08pm) References: <53F67562.2030102@gmx.net> <140822210846.ZM22535@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Bug path completion chsh -s MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Aug 22, 9:08pm, Bart Schaefer wrote: } } Also, chsh has different syntax on different OS's: On MacOS it's an } alias for chpass; on Ubuntu it only has --help and --shell options } (and their -h -s counterparts); on RHEL it has several options and } uses -u instead of -h for --help, and adds -l for --list, both of } which conflict with chpass on MacOs; and so on. So "please fix" is } a rather open-ended request. Having done that research, I went ahead and created an _chsh that I think covers most cases. I don't have BSD handy to test with, but the man page on MacOS claims it is using the BSD chpass. } Maybe somebody else can remind me if there's an easier way to indicate } to _arguments that all the arguments are mutually exclusive. Of course there is, it's just (-). diff --git a/Completion/Unix/Command/.distfiles b/Completion/Unix/Command/.distfiles index fe810e1..35d81b2 100644 --- a/Completion/Unix/Command/.distfiles +++ b/Completion/Unix/Command/.distfiles @@ -29,6 +29,7 @@ _cdrecord _chkconfig _chmod _chown +_chsh _clay _comm _compress diff --git a/Completion/Unix/Command/_chsh b/Completion/Unix/Command/_chsh new file mode 100644 index 0000000..97552e3 --- /dev/null +++ b/Completion/Unix/Command/_chsh @@ -0,0 +1,40 @@ +#compdef chsh chpass +case $OSTYPE in +(darwin*|*bsd*) + _arguments : \ + '-s[Specify user login shell]:shell:(${(Z+Cn+)"$(&/dev/null + then + local -a opts shells + shells=( $(=chsh -l) ) + _arguments : \ + "(-)-s[Specify your login shell]:shell:($shells)" \ + "(-)--shell[Specify your login shell]:shell:($shells)" \ + "(-)-l[Print shells in /etc/shells]" \ + "(-)--list-shells[Print shells in /etc/shells]" \ + "(-)-u[Print a usage message and exit]" \ + "(-)--help[Print a usage message and exit]" \ + "(-)-v[Print version information and exit]" \ + "(-)--version[Print version information and exit]" \ + "1:user name:_users" + return + fi + # else fall through + ;& +(*) + local s='' + # Use $s to cause all options to be treated as mutually exclusive + [[ $words[CURRENT-1] = -* ]] && s="(-)$words[CURRENT-1]" + # This fiddling with $s is a hack to cause "_arguments : --" to use + # the /etc/shells listing for -s or --shell even when the description + # of that option has been pulled from the GNU --help output. + [[ $words[CURRENT-1] = (-s|--shell) ]] && + s="$s"'[ ]:shell:(${(Z+Cn+)"$(