current pwd in prompt

Tim Smith, Knowledgian tim at ism780c.UUCP
Thu Feb 18 08:36:56 AEST 1988


In article <142700023 at occrsh.ATT.COM> rjd at occrsh.ATT.COM writes:
< and I am also running ksh for my login, this was the method that I liked the
< best.  Put into your .profile (or the file that ENV is set to):
< 
< c() {
< 	cd $*
< 	PS1="${PWD}: "
< }
< 
<   And use "c <dirname>" to change directories.

Here is a function that works with the regular shell.  It has some obvious
drawbacks, but it sort of works:

CD=				# holds current directory
ccd() {
	SAVE=$CD
	if [ $# -eq 0 ]
	then
		CD='~'
		NEW=
	else
		NEW=$1
		case $NEW
		in
			/* ) CD=$NEW ;;
			 * ) CD=$CD/$NEW ;;
		esac
	fi
	if cd $NEW
	then
		PS1=$CD
	else
		CD=$SAVE
	fi
	PS1="$CD "
}

use "ccd <dirname>" to change directories.  This will show your home
directory as '~'.
-- 
Tim Smith					tim at ism780c.ism.com
"There is no dark side of the force.  As a matter of fact, it's all dark"



More information about the Comp.unix.wizards mailing list