puder (09/08/82)
Here are some aliases that keep a copy of the directory stack in a shell variable (also in an environment variable). It would be nicer if csh provided this, since it already provides $cwd (HINT:Bill?), but this does work. # extracted from .cshrc : if ($?prompt) then # is this an interactive shell? source ~/.icshrc else # this speeds up non-interactive shell start-up by giving them # the variables, but not the actual directory stack. if ($?ds) then set ds=($ds) else set ds=(`dirs`) endif alias pd pushd # Better aliases could be provided here, but I find that I don't # use them in "shell escape" commands. endif setenv ds "$ds" # extracted from .icshrc : # this file is only done for interactive shells. if ($?ds) then # There may be a way to speed up this loop. If so, it may give # acceptable performance for non-interactive shells as well. set ds=($ds) set dc=$#ds cd $ds[$dc] @ dc-- while ($dc) pushd $ds[$dc]>/dev/null @ dc-- end unset dc else set ds=(`dirs`) endif alias cd 'cd \!*;set ds=(`dirs`);setenv ds "$ds";dirs' alias pd 'pushd \!*;set ds=(`dirs`);setenv ds "$ds"' alias popd 'popd \!*;set ds=(`dirs`);setenv ds "$ds"' Note that both a shell and an environment variable are used. They have the same name to preserve namespace, since the environment variable is only needed by .cshrc to set up the shell variable. As soon as the shell variable is set, the environment variable is hidden. The shell variable is the one that gets used normally, since it can be indexed as an array. The environment variable (which cannot be indexed as easily) is just for passing the stack contents to subshells. The loop that sets up the stack seems to slow start-up considerably for deep stacks, so it is only run if the shell is interactive. If this loop could be speeded up, it would be reasonable to always build the stack. If you have directory names with any pattern characters in them, the code should be bracketed by "set noglob" and "unset noglob". Happy hacking, Karl Puder ...!{houxi,vax135}!lime!burdvax!puder