Article View: comp.unix.shell
Article #1690Re: Csh question: Doing cd .. from a symbolically linked directory
From: Bob Peirce #305
Date: Thu, 01 Nov 1990 13:39
Date: Thu, 01 Nov 1990 13:39
37 lines
2235 bytes
2235 bytes
My brain damaged csh lacks eval and it doesn't set cwd. It also runs on
an Altos with worknet -- top level directories may be / or @node.
However, we do have symbolic links, so here is my solution. I have been
hacking on this for about the last day or two. It now handles 99% of
anything we might want to do here. I would dearly love to know how I
can improve it.
# Handle typical .. moves from a symbolically linked directory
# You can go home, rel, abs, .. or ../something. That's it.
# On an Altos with worknet, / may also be @node
# Some aliases may add extraneous /s so we have to squeeze them
# Logic is to check if you are going home. If not, check the first
# char of the arg to see if it is dot, /, or @.
# If we lead off with a dot and the arg is the same as the tail of
# the arg we are just doing .. Otherwise we are doing ../something.
# If we .. all the way to /, we have to set /.
# If we lead off with / or @ it is absolute.
# If we do not lead off with dot, / or @ it is relative so
# we append the arg to $cwd/.
set cwd = `pwd`
alias cd '\\
set nwd;\\
set tmp;\\
set tgt = \!*;\\
if (x\!* == "x") set nwd = $home;\\
if (x$nwd != x$home) set tmp = `echo \!* | cut -c1`;\\
if ("x\$tmp" == 'x\\\\.' && $tgt == $tgt:t) set nwd = $cwd:h;\\
if ("x\$tmp" == 'x\\\\.' && $tgt != $tgt:t) set nwd = $cwd:h/$tgt:t;\\
if ("x\$tmp" == 'x\\\\.' && $nwd == "") set nwd = /;\\
if (x$nwd != x$home && x$tmp == 'x/' || x$tmp == 'x@') set nwd = \!*;\\
if (x$nwd == "x" && \!* != '..') set nwd = $cwd/\!*;\\
chdir $nwd;\\
set cwd = `echo $nwd | tr -s '/'`'
--
Bob Peirce, Pittsburgh, PA 412-471-5320
...!uunet!pitt!investor!rbp rbp@investor.pgh.pa.us
Technical Details
Message-ID:
<1990Nov1.133909.11337@investor.pgh.pa.us>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!dsl.pitt.edu!pitt!darth!investor.pgh.pa.us!rbpShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!dsl.pitt.edu!pitt!darth!investor.pgh.pa.us!rbp From: rbp@investor.pgh.pa.us (Bob Peirce #305) Newsgroups: comp.unix.shell Subject: Re: Csh question: Doing cd .. from a symbolically linked directory Message-ID: <1990Nov1.133909.11337@investor.pgh.pa.us> Date: 1 Nov 90 13:39:09 GMT Reply-To: rbp@investor.pgh.pa.us (Bob Peirce #305) Organization: Cookson, Peirce & Co., Pittsburgh, PA Lines: 37