[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "cdpath" searching, and pushd/popd too



I have never used cdpath, and I second the motion to remove it from
initial.es.  I can see how people can get addicted to it though, so
putting the code to do so in an interactive.es file is probably a good
idea.

Myself, I have become addicted to pushd and popd, but I will not
suggest adding them to es.  Indeed I find them somewhat painful to
use, even though I use them frequently:  Getting back to a particular
directory requires a `dirs' followed by careful counting to figure out
which number to give to `pushd'.

So I went ahead and implemented a two-argument cd:  If I cd out of a
directory and suspect I may want to get back there some time, I give
an optional second argument to cd.  Then I give that name to cd to get
back there.  The default second arg is `-', so `cd -' acts like many
people's `back'.

Here is my implementation of the thing.

fn-%pwd = <={%whatis pwd}
wd = `` \n %pwd
fn-pwd = {echo $wd}
fn cd to name {
  if {~ $#to 0} \
    {to=$home
     if {!~ $#home 1} {throw error $0 '$home must have one component only'}}
  if {~ $#name 0} {name=-}
  if {!~ $#name 1} {throw error $0 'Usage: cd [dir [return-name]]'}
  if {!~ $#(dir-$to) 0} {to=$(dir-$to); echo cd $to >[1=2]}
  $&cd $to
  dir-$name=$wd
  wd=`` \n {%pwd}
  $%cd-hook}

Sample session:

; cd /etc
; cd -
cd /export/home/hanche
; cd -
cd /etc
; cd /usr etc
; pwd
/usr
; cd etc
cd /etc
; cd -
cd /usr
; cd ./etc
; pwd
/usr/etc

This is still experimental, but I would like to know what others think
of the idea and what other solutions to the same problem people have
come up with.

Oh, there is one problem with this, as well as with the classical
pushd/popd, and with back to:  We have a system where lots of file
system are NFS mounted using the automounter.  Now trying to cd back
to a directory that I didn't visit for a while can easily fail, as I
haven't save the version of the path that will trigger the automounter
to remount the volume.  Any good solutions for that one?

- Harald