current pwd in prompt

Larry McVoy lm at arizona.edu
Thu Feb 11 12:33:01 AEST 1988


In article <1079 at ucdavis.ucdavis.edu> kwok at 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 at arizona.edu or ...!{uwvax,sun}!arizona.edu!lm
		Use the force - read the source.



More information about the Comp.unix.wizards mailing list