Record of some of the computer tech I deal with so that it's documented at least somewhere.

Tuesday, 8 December 2009

cd with cd - feature

On Lunix cd as an extra feature namely cd -
which takes you to the previous directory

I've got quite into this as I jump about, freebsd had pushcd and popcd which was also fun.

fn cd {
cdnextlastdir = `{pwd}
{
if(~ $#* 0)
builtin cd
if not if(~ $1 -)
builtin cd $cdlastdir
if not
builtin cd $1
} && cdlastdir = $cdnextlastdir
}

I've got it in lib/profile

EXAMPLE


t23% cd
t23% pwd
/usr/maht
t23% cd /
t23% pwd
/
t23% cd -
t23% pwd
/usr/maht
t23% cd ouihouihiuh
Can't cd ouihouihiuh: 'ouihouihiuh' file does not exist
t23% cd -
t23% pwd
/
t23% cd -
t23% pwd
/usr/maht
t23%

No comments: