[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
cd tracking symbolic links
(I hesitate to raise this issue, because two years ago we had a long
debate over what the shell should do, but it came up in a private
discussion I was in and, since I wrote the code, I thought someone
might be interested in it. I don't think it's the right thing for the
shell to do, but other people do. Es is about being able to customize
the shell in interesting ways. Vive la difference.)
Enclosed is a spoofing of cd and pwd to give es the same behavior as
(ba k tc z)^sh when cd'ing across symbolic links: with this change,
cd .. always takes one back one directory in the path, not to the
parent directory in on-disk structure.
I believe that this has to be installed before $cdpath searching, if
you use both of them in combination.
Paul
----
# es hack to make cd "follow" symbolic links, so that cd symlink/..
# returns one to the intial directory, not the parent of the directory
# pointed to by the symlink.
fn pwd {
if {~ $#cwd 0} {
noexport = $noexport cwd
cwd = `` \n /bin/pwd
}
echo $cwd
}
let (cd = $fn-cd) fn cd dir {
if {~ $#cwd 0} {
noexport = $noexport cwd
}
if {~ $#dir 0} {
$cd
cwd = ~
} {
let (current = <={
if {~ $dir /*} {
result
} {
if {~ $#cwd 0} {
cwd = `` \n /bin/pwd
}
%split / $cwd
}
}) {
for (name = <={%split / $dir}) {
if {~ $name ..} {
if {!~ $#current 0} {
let (x = 1 $current) current = $x(2 ... $#current)
}
} {!~ $name . ''} {
current = $current $name
}
}
let (path = / ^ <={ %flatten / $current }) {
$cd $path
cwd = $path
}
}
}
}