From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3460 invoked from network); 27 Mar 2008 12:31:52 -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; 27 Mar 2008 12:31:52 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 82474 invoked from network); 27 Mar 2008 12:31:48 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 27 Mar 2008 12:31:48 -0000 Received: (qmail 15281 invoked by alias); 27 Mar 2008 12:31:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24762 Received: (qmail 15265 invoked from network); 27 Mar 2008 12:31:45 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 27 Mar 2008 12:31:45 -0000 Received: from puffy.raveland.org (puffy.raveland.org [195.200.166.230]) by bifrost.dotsrc.org (Postfix) with ESMTP id 6CC7F82CD268 for ; Thu, 27 Mar 2008 13:31:41 +0100 (CET) Received: from localhost.pacwan.net (pea-dsktp.pacwan.net [195.200.191.158]) by puffy.raveland.org (Postfix) with ESMTP id E65B2713467; Thu, 27 Mar 2008 13:31:40 +0100 (CET) Date: Thu, 27 Mar 2008 13:31:37 +0100 From: Pea To: Peter Stephenson Cc: zsh-workers@sunsite.dk Subject: Re: _canonical_path not working on *BSD Message-ID: <20080327133137.58f14ec0@raveland.org> In-Reply-To: <20080327112506.7298e9ef@news01> References: <20080326114413.80713vrmznwpnyuc@bapt.selfip.org> <080326083638.ZM16858@torch.brasslantern.com> <200803261540.m2QFeJmm017381@news01.csr.com> <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> Organization: Raveland X-Mailer: Claws Mail 3.3.0 (GTK+ 2.12.7; i386-unknown-openbsd4.3) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV 0.91.2/6421/Thu Mar 27 09:54:20 2008 on bifrost X-Virus-Status: Clean Le Thu, 27 Mar 2008 11:25:06 +0000, Peter Stephenson a =E9crit : > On Thu, 27 Mar 2008 12:08:07 +0100 > Pea wrote: > > [pea@pea-dsktp:~]% umount > > _canonical_paths_get_canonical_path:unfunction:1: no such hash > > table element: chpwd > > _canonical_paths_get_canonical_path:unfunction:1: no such hash > > table element: chpwd >=20 > I thought unfunction was silent if a function didn't exist, as is now > true of (and required for) unset, but apparently not. >=20 > Since I can't seem to get away from this, I've rewritten the function > more canonically so that the helper functions only get loaded once > and aren't buried in the body of the main function that gets stored. > Most of the patch is consequent rearrangement. >=20 > Index: Completion/Unix/Type/_canonical_paths > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_canonical_paths,v > retrieving revision 1.3 > diff -u -r1.3 _canonical_paths > --- Completion/Unix/Type/_canonical_paths 27 Mar 2008 10:35:21 > -0000 1.3 +++ Completion/Unix/Type/_canonical_paths 27 > Mar 2008 11:20:34 -0000 @@ -13,27 +13,13 @@ > # case they are already so. `tag' and `desc' arguments are well, > obvious :) In # addition, the options -M, -J, -V, -1, -2, -n, -F, -X > are passed to compadd.=20 > -local __index > -typeset -a __gopts __opts > - > -zparseopts -D -a __gopts M: J: V: 1 2 n F: X: A:=3D__opts N=3D__opts > - > -: ${1:=3Dcanonical-paths} ${2:=3Dpath} > - > -__index=3D$__opts[(I)-A] > -(( $__index )) && set -- $@ ${(P)__opts[__index+1]} > - > -local expl ret=3D1 tag=3D$1 desc=3D$2 > - > -shift 2 > - > -if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then > - _wanted "$tag" expl "$desc" compadd $__gopts $@ && ret=3D0 > - return ret > -fi > - > -typeset REPLY > -typeset -a matches files > +_canonical_paths_pwd() { > + # Get the canonical directory name by changing to it. > + # To be run in a subshell. > + (( ${+functions[chpwd]} )) && unfunction chpwd > + setopt CHASE_LINKS > + cd $1 2>/dev/null && pwd > +} > =20 > _canonical_paths_get_canonical_path() { > typeset newfile dir > @@ -55,34 +41,20 @@ > # Canonicalise the directory path. We may not be able to > # do this if we can't read all components. > if [[ -d $REPLY ]]; then > - dir=3D"$(unfunction chpwd > - setopt CHASE_LINKS > - cd $REPLY 2>/dev/null && pwd)" > + dir=3D"$(_canonical_paths_pwd $REPLY)" > if [[ -n $dir ]]; then > REPLY=3D$dir > fi > elif [[ $REPLY =3D */*[^/] && $REPLY !=3D /[^/]# ]]; then > # Don't try this if there's a trailing slash or we're in > # the root directory. > - dir=3D"$(unfunction chpwd > - setopt CHASE_LINKS > - cd ${REPLY%/*} 2>/dev/null && pwd)" > + dir=3D"$(_canonical_paths_pwd ${REPLY%/*})" > if [[ -n $dir ]]; then > REPLY=3D$dir/${REPLY##*/} > fi > fi > } > =20 > - > -if (( $__opts[(I)-N] )); then > - files=3D($@) > -else > - for __index in $@; do > - _canonical_paths_get_canonical_path $__index > - files+=3D($REPLY) > - done > -fi > - > _canonical_paths_add_paths () { > local origpref=3D$1 expref rltrim curpref canpref subdir > [[ $2 !=3D add ]] && matches=3D() > @@ -104,35 +76,70 @@ > done > } > =20 > -local base=3D$PREFIX > -typeset -i blimit > +_canonical_paths() { > + local __index > + typeset -a __gopts __opts > + > + zparseopts -D -a __gopts M: J: V: 1 2 n F: X: A:=3D__opts N=3D__opts > + > + : ${1:=3Dcanonical-paths} ${2:=3Dpath} > + > + __index=3D$__opts[(I)-A] > + (( $__index )) && set -- $@ ${(P)__opts[__index+1]} > =20 > -_canonical_paths_add_paths $base > + local expl ret=3D1 tag=3D$1 desc=3D$2 > =20 > -if [[ -z $base ]]; then > - _canonical_paths_add_paths / add > -elif [[ $base =3D=3D ..(/.(|.))#(|/) ]]; then > - > - # This style controls how many parent directory links (..) to > chase searching > - # for possible completions. The default is 8. Note that this > chasing is > - # triggered only when the user enters atleast a .. and the path > completed > - # contains only . or .. components. A value of 0 turns off .. link > chasing > - # altogether. > - > - zstyle -s ":completion:${curcontext}:$tag" \ > - canonical-paths-back-limit blimit || blimit=3D8 > - > - if [[ $base !=3D */ ]]; then > - [[ $base !=3D *.. ]] && base+=3D. > - base+=3D/ > + shift 2 > + > + if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then > + _wanted "$tag" expl "$desc" compadd $__gopts $@ && ret=3D0 > + return ret > fi > - until [[ $base.. -ef $base || blimit -le 0 ]]; do > - base+=3D../ > - _canonical_paths_add_paths $base add > - blimit+=3D-1 > - done > -fi > =20 > -_wanted "$tag" expl "$desc" compadd $__gopts -Q -U -a matches && > ret=3D0 > + typeset REPLY > + typeset -a matches files > + > + if (( $__opts[(I)-N] )); then > + files=3D($@) > + else > + for __index in $@; do > + _canonical_paths_get_canonical_path $__index > + files+=3D($REPLY) > + done > + fi > + > + local base=3D$PREFIX > + typeset -i blimit > + > + _canonical_paths_add_paths $base > + > + if [[ -z $base ]]; then > + _canonical_paths_add_paths / add > + elif [[ $base =3D=3D ..(/.(|.))#(|/) ]]; then > + > + # This style controls how many parent directory links (..) to > chase searching > + # for possible completions. The default is 8. Note that this > chasing is > + # triggered only when the user enters atleast a .. and the path > completed > + # contains only . or .. components. A value of 0 turns off .. > link chasing > + # altogether. > + > + zstyle -s ":completion:${curcontext}:$tag" \ > + canonical-paths-back-limit blimit || blimit=3D8 > + > + if [[ $base !=3D */ ]]; then > + [[ $base !=3D *.. ]] && base+=3D. > + base+=3D/ > + fi > + until [[ $base.. -ef $base || blimit -le 0 ]]; do > + base+=3D../ > + _canonical_paths_add_paths $base add > + blimit+=3D-1 > + done > + fi > + > + _wanted "$tag" expl "$desc" compadd $__gopts -Q -U -a matches && > ret=3D0 + > + return ret > +} > =20 > -return ret > +_canonical_paths "$@" >=20 This works fine on OpenBSD. Regards, --=20 Pierre-Emmanuel Andr=E9 GPG key: 0x7AE329DC