Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site wateng.UUCP Path: utzoo!watmath!wateng!ksbszabo From: ksbszabo@wateng.UUCP (Kevin Szabo) Newsgroups: net.sources Subject: Re: pushd/popd wanted (from net.wanted.sources) Message-ID: <2385@wateng.UUCP> Date: Tue, 14-May-85 13:07:21 EDT Article-I.D.: wateng.2385 Posted: Tue May 14 13:07:21 1985 Date-Received: Wed, 15-May-85 00:34:16 EDT References: <1798@watcgl.UUCP> Reply-To: ksbszabo@wateng.UUCP (Kevin Szabo) Distribution: net Organization: VLSI Group, U of Waterloo Lines: 61 Summary: Ahh, time to post some cryptic aliases! :-) Seriously, it is a sufficiently difficult/un-obvious problem that I think my posting is justified. Please no flames about CSH etc. Thanks. ------------------------------------------------------- Pushd and Popd are built into some CSH. However, many CSH don't have them. I don't think you can really simulate the action in Bourne shell, but these CSH aliases will provide the necessary effect. Note that they depend on the existance of the $cwd shell variable. If your shell doesn't provide the psuedo-variable $cwd you will have to use the alias for CD as well. -- Kevin P.S. These aliases are currently in use on a vax based BSD4.2 system and a microsoft port of SysIII with 'berkeley enhancements' running on a orcatech3000 (m68k based). --------------- put in your .cshrc ----------------- #is this an interactive shell? if ( $?prompt ) then source ~/.aliases endif --------------- put in your ~/.aliases file ------------------ # pushd, popd simulator set dir #if dir is not set you will get errors # pushd, popd simulator; uses my own directory stack alias pd 'set dir=($dir "" "") dest=\!* dir[1]=$cwd;'\ 'if ( $dest == "" ) set dest=$dir[2] dir[2]="";'\ 'cd $dest;'\ 'set dir = ($cwd $dir);'\ 'echo $dir;' alias dp 'set dir[1]="";set dir=($dir "");cd $dir[1];echo $dir' # alias for CD provides a $cwd (current working directory) variable alias cd 'chdir \!*;set cwd=`/bin/pwd`;' alias dirs 'echo $dir' cd . # set the $cwd variable immediately # If you want to have a prompt that holds parts of the current directory... alias cd 'chdir \!*;set cwd=`/bin/pwd`;\\ set head=$cwd:h; set prompt="$USER [$head:t/$cwd:t] \! % "' ---------------------------------------------------------- If you want to see these babies in action, try setting the shell variables 'verbose' and 'echo'. You will get a blow by blow listing of the shell's gyrations. -- Kevin Szabo watmath!wateng!ksbszabo (U of Waterloo VLSI Group, Waterloo Ont.)