pushd/popd wanted (from net.wanted.sources)
Kevin Szabo
ksbszabo at wateng.UUCP
Wed May 15 03:07:21 AEST 1985
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.)
More information about the Comp.sources.unix
mailing list