From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25888 invoked from network); 28 Mar 2008 14:36:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 28 Mar 2008 14:36:00 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 62328 invoked from network); 28 Mar 2008 14:35:55 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 28 Mar 2008 14:35:55 -0000 Received: (qmail 6235 invoked by alias); 28 Mar 2008 14:35:52 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24775 Received: (qmail 6220 invoked from network); 28 Mar 2008 14:35:51 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 28 Mar 2008 14:35:51 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [85.115.41.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id 939CC82CD273 for ; Fri, 28 Mar 2008 15:35:46 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly10g.srv.mailcontrol.com (MailControl) with ESMTP id m2SEYOgE019602 for ; Fri, 28 Mar 2008 14:35:31 GMT Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Fri, 28 Mar 2008 14:35:17 +0000 Date: Fri, 28 Mar 2008 14:35:17 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: PATCH: cd -q (was Re: _canonical_path ...) Message-ID: <20080328143517.7785de01@news01> In-Reply-To: <237967ef0803280401o7176d1c1n5e037a0574e8998e@mail.gmail.com> References: <20080326114413.80713vrmznwpnyuc@bapt.selfip.org> <200803261604.m2QG41Ke017772@news01.csr.com> <200803261621.m2QGLptV017966@news01.csr.com> <20080326173824.0a55c00d@coredump.raveland.priv> <20080326164615.1d5893ed@news01> <20080327102325.55808716@news01> <20080327120807.415095ee@raveland.org> <20080327112506.7298e9ef@news01> <20080327121525.5b4059f9@news01> <20080327184502.09b2a535@news01> <237967ef0803280401o7176d1c1n5e037a0574e8998e@mail.gmail.com> Organization: CSR X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.5; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 28 Mar 2008 14:35:17.0893 (UTC) FILETIME=[F1818350:01C890E0] X-Scanned-By: MailControl A-08-00-04 (www.mailcontrol.com) on 10.71.0.120 X-Virus-Scanned: ClamAV 0.91.2/6440/Fri Mar 28 14:37:20 2008 on bifrost X-Virus-Status: Clean On Fri, 28 Mar 2008 12:01:15 +0100 "Mikael Magnusson" wrote: > I couldn't help but notice _cd doesn't complete directories after -q > (or -L or -P or -s) Yes, this is a long-standing bug and it's easy enough to teach it to ignore options (remembering that -<-> is not an option). > nor the options themselves. This is less than easy enough to get working normally because we don't use _arguments. Probably the best thing to do is to use _arguments at the top level and dispatch to the current code for first or second arguments. Until then I've made it complete options only after a -, where it also completes directory stack entries. Since completing directory stack entries is much more useful (at least with verbose listing) and the vast majority of the time the options are just in the way I've added a style to suppress option completions. Normally this would be done with tags but in this case I think we need them separate by default. This all seems to make rather heavy weather of something fairly simple. Index: Completion/Zsh/Command/_cd =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_cd,v retrieving revision 1.7 diff -u -r1.7 _cd --- Completion/Zsh/Command/_cd 3 Sep 2003 14:07:26 -0000 1.7 +++ Completion/Zsh/Command/_cd 28 Mar 2008 14:33:02 -0000 @@ -11,17 +11,37 @@ # it's not a lot of use. If you don't type the + or - it will # complete directories as normal. +_cd_options() { + _arguments -s \ + '-q[Quiet, no output or use of hooks]' \ + '-s[Refuse to use paths with symlinks]' \ + '(-P)-L[Retain symbolic links ignoring CHASE_LINKS]' \ + '(-L)-P[Resolve symbolic links as CHASE_LINKS]' +} + setopt localoptions nonomatch -local expl ret=1 +local expl ret=1 curarg +integer argstart=2 noopts + +if (( CURRENT > 1 )); then + # if not in command position, may have options. + # Careful: -<-> is not an option. + while [[ $words[$argstart] = -* && argstart -lt CURRENT ]]; do + curarg=$words[$argstart] + [[ $curarg = -<-> ]] && break + (( argstart++ )) + [[ $curarg = -- ]] && noopts=1 && break + done +fi -if [[ CURRENT -eq 3 ]]; then +if [[ CURRENT -eq $((argstart+1)) ]]; then # cd old new: look for old in $PWD and see what can replace it local rep # Get possible completions using word in position 2 - rep=(${~PWD/$words[2]/*}~$PWD(-/)) + rep=(${~PWD/$words[$argstart]/*}~$PWD(-/)) # Now remove all the common parts of $PWD and the completions from this - rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}}) + rep=(${${rep#${PWD%%$words[$argstart]*}}%${PWD#*$words[$argstart]}}) (( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep else # Complete directory stack entries with ~ or when not in command position @@ -70,6 +90,11 @@ [[ CURRENT -ne 1 || ( -z "$path[(r).]" && $PREFIX != */* ) ]] && alt=( "${cdpath+local-}directories:${cdpath+local }directory:_path_files -/" "$alt[@]" ) + if [[ CURRENT -eq argstart && noopts -eq 0 && $PREFIX = -* ]] && + zstyle -t ":completion:${curcontext}:options" complete-options; then + alt=("$service-options:$service option:_cd_options" "$alt[@]") + fi + _alternative "$alt[@]" && ret=0 return ret Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.205 diff -u -r1.205 compsys.yo --- Doc/Zsh/compsys.yo 28 Feb 2008 18:29:05 -0000 1.205 +++ Doc/Zsh/compsys.yo 28 Mar 2008 14:33:05 -0000 @@ -1221,6 +1221,16 @@ line is not the name of an alias, matching alias names will be completed. ) +kindex(complete-options, completion style) +time(tt(complete-options))( +This is used by the completer for tt(cd), tt(chdir) and tt(pushd). +For these commands a tt(-) is used to introduce a directory stack entry +and completion of these is far more common than completing options. +Hence unless the value of this style is true options will not be +completed, even after an initial tt(-). If it is true, options will +be completed after an initial tt(-) unless there is a preceeding +tt(--) on the command line. +) kindex(completer, completion style) item(tt(completer))( The strings given as the value of this style provide the names of the -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070