Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: Problem with _cd return code
- X-seq: zsh-workers 12769
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: Re: Problem with _cd return code
- Date: Thu, 7 Sep 2000 10:55:15 +0200 (MET DST)
- In-reply-to: Sven Wischnowsky's message of Mon, 28 Aug 2000 09:13:23 +0200 (MET DST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
I wrote:
> Andrej Borsenkow wrote:
>
> > ... when completing directory stack (cd -TAB). It completes it alright, but it
> > always beeps; and sometimes I get additionally external directories listed.
> >
> > It looks like return code problem, but I could not figure out how to fix it. I
> > do not quite understand, what _wanted, _requested etc are supposed to return.
>
> The same as all completion functions, of course: zero if matches were
> added, non-zero otherwise.
>
> What's happening is quite easy to see in _cd. That calls _popd for the
> directory stack like this:
>
> elif _popd || [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
>
> So, if _popd succeeds (adds matches), we go on completing, forgetting
> about the zero-return from _popd and instead using the return value of
> one of the calls to _wanted or the return value from _alternative as
> the result of _cd.
>
> We should probably change that to something like:
>
> else
> _popd && ret=0
> if [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
> ...
> else
> ...
> fi
> return ret
> fi
>
> Unless I'm missing something that was intended by whoever wrote that.
There was no reply and since it still seemed sensible after looking
again, here is the patch.
This may be my last patch until the beginning of october. Holiday. Hurray.
Bye
Sven
P.S.: Most of the patch is only re-indentation.
Index: Completion/Builtins/_cd
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_cd,v
retrieving revision 1.3
diff -u -r1.3 _cd
--- Completion/Builtins/_cd 2000/05/31 09:38:26 1.3
+++ Completion/Builtins/_cd 2000/09/07 08:54:25
@@ -13,7 +13,7 @@
setopt localoptions nonomatch
-local expl
+local expl ret=1
if [[ CURRENT -eq 3 ]]; then
# cd old new: look for old in $PWD and see what can replace it
@@ -23,25 +23,32 @@
# Now remove all the common parts of $PWD and the completions from this
rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
(( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep
-elif _popd || [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
- local tdir tdir2
+else
+ _popd && ret=0
+
+ if [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then
+ local tdir tdir2
- # With cdablevars, we can convert foo/bar/... to ~foo/bar/... if
- # there is no directory foo. In that case we could also complete
- # variable names, but it hardly seems worth it.
- # Note we need a tilde because cdablevars also allows user home
- # directories, hence we also need nonomatch to suppress error messages.
- if [[ -o cdablevars && -n "$PREFIX" && ! -d ${tdir::=${PREFIX%%/*}} &&
- -d ${~tdir2::="~$tdir"} ]]; then
+ # With cdablevars, we can convert foo/bar/... to ~foo/bar/... if
+ # there is no directory foo. In that case we could also complete
+ # variable names, but it hardly seems worth it.
+ # Note we need a tilde because cdablevars also allows user home
+ # directories, hence we also need nonomatch to suppress error messages.
+ if [[ -o cdablevars && -n "$PREFIX" && ! -d ${tdir::=${PREFIX%%/*}} &&
+ -d ${~tdir2::="~$tdir"} ]]; then
PREFIX="~$PREFIX"
- _wanted directories expl directory _path_files -/
+ _wanted directories expl directory _path_files -/ && ret=0
+ else
+ local tmpcdpath
+
+ tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
+ _alternative \
+ 'local-directories:local directories:_path_files -/' \
+ "path-directories:directories in cdpath:_path_files -W tmpcdpath -/" && ret=0
+ fi
else
- local tmpcdpath
- tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
- _alternative \
- 'local-directories:local directories:_path_files -/' \
- "path-directories:directories in cdpath:_path_files -W tmpcdpath -/"
+ _wanted directories expl directory _path_files -/ && ret=0
fi
-else
- _wanted directories expl directory _path_files -/
+
+ return ret
fi
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author