Using the directory stack like !-2:3 in csh

Root Boy Jim rbj at icst-cmr.arpa
Sat May 28 12:49:05 AEST 1988


   You can use the 'dirs' command, and alias the usual directory commands 
   in the following manner:

   - include the following shell variable initialization in your .login
	   set d=$HOME

   - and add three lines to your .cshrc
	   alias cd    'cd \!*;set d=`dirs`'
	   alias pushd 'pushd \!*; set d=`dirs`'
	   alias popd  'popd; set d=`dirs`'

   In that way, your directory stack is always saved in $d[1], $d[2], ... with
   $d[1] being your current working directory.

Even better is to replace `d' with `argv', then you can just reference
$1, $2, etc! BTW, popd should have a \!* as well, to handle `popd +2', etc.
Strictly speaking, the set command should have parens around the dirs
command, altho it seems to work anyway, probably because of the order
in which command substitution, blank interpretation, and builtin commands
are handled. Note to Paul Placeway: given this technique, there is no
reason to support the `=<num>' construct in tcsh, altho I do appreciate
its being there. Now to fix up my aliases...

   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
   Steve Lane,              UUCP: ...[mnetor, yunexus, utgpu]!geac!steve
   Geac Computers International Inc.
   Markham, Ontario.  (416) 475-0525

	(Root Boy) Jim Cottrell	<rbj at icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
	The opinions expressed are solely my own
	and do not reflect NBS policy or agreement
	My name is in /usr/dict/words. Is yours?



More information about the Comp.unix.wizards mailing list