Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Directory completion acts as if CHASE_LINKS is set
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author