dongre@optilink.UUCP (Sumit Dongre) (01/19/89)
Is there a way to track/recover the last few directories in ksh-i. I don't have source, I've written functions to help me do this...but I'm just wonderin' if ksh already tracks a list of directories other than the last one...someone told me that ksh has the capability to track up to 32 previous directories...but that's all I was told...
lfk@mbio.med.upenn.edu (Lee Kolakowski) (01/19/89)
According to the book (Morris Bolsky, David Korn, The Korn Shell, Prentice Hall, 1989, ISBN 0-13-516972-0), there are no built-in mechanisms for the pushd/popd/dirs/roll utilities, however there are several pages describing the shell functions to do this. -- Frank Kolakowski ____________________________________________________________________________ |lfk@mbio.med.upenn.edu || Lee F. Kolakowski | |kolakowski@mscf.med.upenn. || Univ. of Penna. | |c/o jes@eniac.seas.upenn.edu || Dept of Chemistry | |kolakowski%c.chem.upenn.edu@relay.upenn.edu || 231 South 34th St. | |kolakowski%d.chem.upenn.edu@relay.upenn.edu || Phila, PA 19104 | |bcooperman.kolakowski@bionet-20.arpa ||--------------------------| |AT&T: 1-215-898-2927 || One-Liner Here! | =============================================================================
jack@cs.glasgow.ac.uk (Jack Campin) (01/23/89)
dongre@optilink.UUCP (Sumit Dongre) wrote: Is there a way to track/recover the last few directories in ksh-i. I don't have source, I've written functions to help me do this...but I'm just wonderin' if ksh already tracks a list of directories other than the last one...someone told me that ksh has the capability to track up to 32 previous directories...but that's all I was told... I wrote a few ksh functions to support a "working set" model of directories; you have a cache of directories you can switch between with a "select" menu interface, edit, save, and load. I can post them here if people are interested (I would have sent it to comp.sources.misc, but couldn't reach the moderator by email). About 7K, and 11K documentation (most of the complication comes from handling directories with spaces in their names, which we have a LOT of round here). I have no idea what ksh-i is, so don't know if they'll work with it. -- Jack Campin * Computing Science Department, Glasgow University, 17 Lilybank Gardens, Glasgow G12 8QQ, SCOTLAND. 041 339 8855 x6045 wk 041 556 1878 ho INTERNET: jack%cs.glasgow.ac.uk@nss.cs.ucl.ac.uk USENET: jack@glasgow.uucp JANET: jack@uk.ac.glasgow.cs PLINGnet: ...mcvax!ukc!cs.glasgow.ac.uk!jack
df@nud.UUCP (Dale Farnsworth) (01/25/89)
Sumit Dongre (dongre@optilink.UUCP) writes: > Is there a way to track/recover the last few directories in ksh-i. No, but I added three options to cd via ksh functions. 1. cd -l Displays the most recently used 20 current directories. 2. cd -foostring Changes directory to the most recent directory whose name contains the string foostring. 3. cd -8 Changes to the eighth most recent directory. The directory list is maintained in most recently used order. Here are the functions: # If you want multiple shells to share the same history (either # concurrently or serially, create a file and place its name in # the shell variable CDHISTFILE. alias cd=_cd function _cd { typeset -i cdlen i status typeset t if [ $# -eq 0 ] then set -- $HOME fi t="$@" if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] then typeset CDHIST= set -- `<$CDHISTFILE` ((i=-1)) while [ $# -gt 0 ] do CDHIST[i=i+1]=$1 shift done fi set -- $t if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ] then _cdins fi cdlen=${#CDHIST[*]} case "$@" in -) if [ "$OLDPWD" = "" ] && ((cdlen>1)) then print ${CDHIST[1]} 'cd' ${CDHIST[1]} ; status=$? else 'cd' $@ ; status=$? fi ;; -l) typeset -R3 num ((i=cdlen)) while (((i=i-1)>=0)) do ((num=i)) print "$num ${CDHIST[i]}" done return 0 ;; -[0-9]|-[0-9][0-9]) if (((i=${1#-})<cdlen)) then print ${CDHIST[i]} 'cd' ${CDHIST[i]} ; status=$? else 'cd' $@ ; status=$? fi ;; -*) t=${1#-} ((i=0)) while (((i=i+1)<cdlen)) do case ${CDHIST[i]} in *$t*) print ${CDHIST[i]} 'cd' ${CDHIST[i]} ; status=$? break ;; esac done if ((i>=cdlen)) ; then 'cd' $@ ; status=$? fi ;; *) 'cd' $@ ; status=$? ;; esac _cdins if [ "$CDHISTFILE" ] then print -r ${CDHIST[*]} >$CDHISTFILE fi # set_prompt return $status } function _cdins { typeset -i i ((i=-1)) while (((i=i+1)<${#CDHIST[*]})) do if [ "${CDHIST[$i]}" = "$PWD" ] then break fi done if ((i>20)) then ((i=20)) fi while (((i=i-1)>=0)) do CDHIST[i+1]=${CDHIST[i]} done CDHIST[0]=$PWD } -Dale -- Dale Farnsworth 602-438-3092 noao!asuvax!nud!df