From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10927 invoked by alias); 5 Sep 2013 15:31:29 -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: 31701 Received: (qmail 2598 invoked from network); 5 Sep 2013 15:31:23 -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: <130905083139.ZM29859@torch.brasslantern.com> Date: Thu, 05 Sep 2013 08:31:39 -0700 In-reply-to: Comments: In reply to Jan Larres "Directory completion acts as if CHASE_LINKS is set" (Sep 5, 1:23pm) References: 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 5, 1:23pm, Jan Larres wrote: } } I recently noticed that completion of directories acts as if the } CHASE_LINKS option is set, that is if you are in a symlinked directory } and you want to complete its siblings then it will complete using the } physical siblings instead of the ones from the directory that the } symlink resides in. "cd" itself is smart enough to interpret "../foo" as a physical path when using it as a symbolic path does not work, so the completion list in this example is incomplete rather than incorrect, which is probably why no one has ever noticed. In any case, this is a problem inherent in the way globbing interprets "../" -- filename generation does not obey the same rules as "cd" path resolution. torch% print ../*(/) ../bar ../foo torch% print $PWD:h/*(/) /tmp/cdtest/foo/baz Completion uses globbing to generate the target file names, so this has to be fixed up somehow in _cd before _path_files is called. This patch is a step in the right direction, but has the side-effect of expanding ".." into $PWD:h which is probably not desirable. There may be other nuances [particularly with completion in the middle of a word] that are not handled. So I'm not going to commit it, just presenting it for purposes of discussion. diff --git a/Completion/Zsh/Command/_cd b/Completion/Zsh/Command/_cd index 476947f..9c82a2f 100644 --- a/Completion/Zsh/Command/_cd +++ b/Completion/Zsh/Command/_cd @@ -51,6 +51,14 @@ else _directory_stack && ret=0 fi + if [[ $PREFIX = (|*/)..(|/*) ]]; then + local tmpprefix + # Use cd in a subshell to properly [not] resolve symlinks + tmpprefix=$(cd $PREFIX >&/dev/null && print $PWD) || + tmpprefix=$(cd $PREFIX:h >&/dev/null && print $PWD/$PREFIX:t) + [[ -n $tmpprefix ]] && PREFIX=$tmpprefix + fi + if [[ $PREFIX != (\~|/|./|../)* ]]; then local tmpcdpath alt -- Barton E. Schaefer