From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7321 invoked by alias); 8 Sep 2013 21:27:07 -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: 31712 Received: (qmail 24580 invoked from network); 8 Sep 2013 21:26:51 -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 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130908142628.ZM27141@torch.brasslantern.com> Date: Sun, 08 Sep 2013 14:26:28 -0700 In-reply-to: <20130908185136.711ad4ca@pws-pc.ntlworld.com> Comments: In reply to Peter Stephenson "Re: Directory completion acts as if CHASE_LINKS is set" (Sep 8, 6:51pm) References: <130905083139.ZM29859@torch.brasslantern.com> <20130906210938.30f56d8e@pws-pc.ntlworld.com> <130906220300.ZM31578@torch.brasslantern.com> <20130908185136.711ad4ca@pws-pc.ntlworld.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Directory completion acts as if CHASE_LINKS is set MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Sep 6, 10:03pm, Bart Schaefer wrote: > > On Sep 6, 9:09pm, Peter Stephenson wrote: > } > } You're probably going to be better off using ${PREFIX:a} rather than > } cd. > > No, sorry, that doesn't work; :a behaves like globbing and CHASE_DOTS: > > torch% print $PWD > /tmp/cdtest/foo/bar > torch% x=.. > torch% print $x:a > /tmp/cdtest Hmm, I just noticed that :a does work like "cd" IF there is a path prefix, that is, if "../" is not at the beginning of the value: torch% x=$PWD/.. torch% print $x $x:a /tmp/cdtest/foo/bar/.. /tmp/cdtest/foo So it might be possible to use :a, but it'd need a condition on the form of $PREFIX. However, the other bit that is simplified by doing a real "cd" in a subshell is that cdablevars et al. are taken care of. I suppose you could argue "that's cheating, it's important to avoid the fork" ... but I've spent enough time on this as it is, someone else can take over from here. On Sep 8, 6:51pm, Peter Stephenson wrote: } Subject: Re: Directory completion acts as if CHASE_LINKS is set } } > } I also wonder if it would be better only to look at previous } > } directory components, i.e. always take the PREFIX up to the last "/" } } I'm thinking of something like ${PREFIX%/*}. Ah, I see. Yes, that does work, and furthermore gave me the clue that I needed to get the commmand line handling right. Remaining question is whether to use ${IPREFIX}${PREFIX%/*}. I did in the assignment but not in the $(cd ...) as I can't think of a case for cd where IPREFIX would have a useful value. diff --git a/Completion/Zsh/Command/_cd b/Completion/Zsh/Command/_cd index 476947f..5b581e7 100644 --- a/Completion/Zsh/Command/_cd +++ b/Completion/Zsh/Command/_cd @@ -51,6 +51,18 @@ else _directory_stack && ret=0 fi + local -a tmpWpath + if [[ $PREFIX = (|*/)../* ]]; then + local tmpprefix + # Use cd in a subshell to properly [not] resolve symlinks + tmpprefix=$(cd ${PREFIX%/*} >&/dev/null && print $PWD) + if [[ -n $tmpprefix ]]; then + tmpWpath=(-W $tmpprefix) + IPREFIX=${IPREFIX}${PREFIX%/*}/ + PREFIX=${PREFIX##*/} + fi + fi + if [[ $PREFIX != (\~|/|./|../)* ]]; then local tmpcdpath alt @@ -100,7 +112,7 @@ else return ret fi [[ CURRENT -ne 1 ]] && _wanted directories expl directory \ - _path_files -/ && ret=0 + _path_files $tmpWpath -/ && ret=0 return ret fi