From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Directory completion acts as if CHASE_LINKS is set
Date: Sun, 08 Sep 2013 14:26:28 -0700 [thread overview]
Message-ID: <130908142628.ZM27141@torch.brasslantern.com> (raw)
In-Reply-To: <20130908185136.711ad4ca@pws-pc.ntlworld.com>
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
next prev parent reply other threads:[~2013-09-08 21:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-05 1:23 Jan Larres
2013-09-05 2:15 ` Jan Larres
2013-09-05 15:31 ` Bart Schaefer
2013-09-06 1:42 ` Jan Larres
2013-09-06 6:13 ` Bart Schaefer
2013-09-06 6:46 ` Jan Larres
2013-09-06 20:09 ` Peter Stephenson
2013-09-07 5:03 ` Bart Schaefer
2013-09-08 17:51 ` Peter Stephenson
2013-09-08 21:26 ` Bart Schaefer [this message]
2013-09-09 9:59 ` Peter Stephenson
2013-09-10 14:26 ` Bart Schaefer
2013-09-10 22:34 ` Jan Larres
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=130908142628.ZM27141@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).