[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "cdpath" searching, and pushd/popd too
>>>>> On Tue, 25 May 1993 22:39:55 -0400, Doug.Landauer@Eng.Sun.COM
>>>>> (Doug Landauer) said:
Doug> Likewise. *ALL* of my change-dir commands do a "pushd"-equivalent.
Doug> I use a "z" command instead of "cd" and it *always* pushes the directory.
Doug> [...] If there's interest, I may find the time to sanitize &
Doug> share the es code that does this. It's pretty easy to do,
Doug> though -- much easier in es than it was in [gasp] ksh.
Hmmm... yes, certainly an interesting approach. Since I just invented
this scheme of my own, however, I prefer to play with it for a while
rather than jumping on something else, so I can find out if my idea
was any good or not. I'll keep your offer in mind, though.
Also, thanks to the many folks who suggested ways to coexist with the
automounter. In case anybody out there want to play with my
two-argument cd, I include below the code out of my .esrc that handles
it. Central to the solution is a function %cwd which returns a
sanitized version of the current directory. It even works with
directory names containing newlines and other white space (I think (:-)).
- Harald
## NOTE site specific stuff here: Automounted directories have path
# names beginning /tmp_mnt. This version of %cwd, which returns the
# current directory, strips off the leading component of those directories.
let (pwd = <={%whatis pwd}) {
fn-%cwd= {
let (t = `` () {$pwd}; n =) {
t = <={%fsplit \n $t}; n = $#t; t = . $t; t = $t(2 ... $n);
t = <={%flatten \n $t}
if {~ $t ''} {throw error $0 $pwd ^ ' returned nothing!?'}
if {~ $t /tmp_mnt*} {
t = <={%split / $t}
t = / ^ <={%flatten / $t(2 ...)}}
result $t}}}
wd = <={%cwd}
fn-pwd = {echo $wd}
fn cd to name {
if {~ $#to 0} \
{to=$home
if {!~ $#home 1} {throw error $0 '$home must have just one component'}}
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= <={%cwd}
$%cd-hook}
fn dirs {each @ v{~ $v dir-* && var $v} <=$&vars}