Path: utzoo!mnetor!uunet!husc6!hao!noao!arizona!lm From: lm@arizona.edu (Larry McVoy) Newsgroups: comp.unix.wizards Subject: Re: current pwd in prompt Message-ID: <3811@megaron.arizona.edu> Date: 11 Feb 88 02:33:01 GMT References: <11657@brl-adm.ARPA> <17877@topaz.rutgers.edu> <1079@ucdavis.ucdavis.edu> Reply-To: lm@megaron.arizona.edu.UUCP (Larry McVoy) Organization: University of Arizona, Tucson Lines: 40 In article <1079@ucdavis.ucdavis.edu> kwok@iris.UUCP (Conrad Kwok) writes: > >I have a program to set my prompt to the current directory. Using the Jeez, louise, run a program everytime you cd??? Argggg. Here's a ksh version that also extends ksh's "cd -" to "cd --" and "cd ---" to get the last three dirs you were in (so my cache is small; you make it bigger). By some strange coincidence it also does the ~ trick. Hmmmm.... oh yeah, you also get $OLDPWD1 and $OLDPWD as well as the normal $OLDPWD. Sometimes useful. --- cut here and feed to ksh ---- function _cd { SAVEPWD1=$OLDPWD SAVEPWD2=$OLDPWD1 case $1 in --) 'cd' $OLDPWD1;; ---) 'cd' $OLDPWD2;; *) 'cd' $1;; esac OLDPWD2=$SAVEPWD2 OLDPWD1=$SAVEPWD1 case $PWD in $HOME*) PS1=~"${PWD##$HOME} ";; *) PS1="$PWD ";; esac } function dirs { print "$OLDPWD $OLDPWD1 $OLDPWD2" } alias d=dirs alias cd=_cd alias CD='cd' -- Larry McVoy lm@arizona.edu or ...!{uwvax,sun}!arizona.edu!lm Use the force - read the source.