Subject: Re: pkg/16226 (new patch for review)
To: None <tech-userlevel@netbsd.org>
From: Christopher Richards <richards+netbsd@CS.Princeton.EDU>
List: tech-userlevel
Date: 01/18/2003 13:46:14
On 18 Jan 2003 10:51:46 GMT, Julio Merino wrote:

> Hello,
> 
> here is a new patch to do the prompt expansion thing I submitted some time
> ago. It seems better to me (now memory is only allocated once, and realloc's
> are avoided when possible).

There's really no need to add this to the /bin/sh source.  Just put
the following (or similar) into .shrc.  Or, use bash.  One caveat: the
"command" builtin of /bin/sh is currently broken, so this will only
work on /bin/ksh at the moment.

# Print the working directory, etc. in the prompt
_user=`whoami`
_host=`hostname`
_host_short=${_host%%.*}

cd_prompt () {
    command cd "$@"
    export PWD
    case $PWD in
	$HOME*) PS1="${_host_short}:~${PWD##${HOME}}" ;;
	*)      PS1="${_host_short}:$PWD" ;;
    esac
    case $TERM in 
	xterm*|rxvt*|cygwin) 
	echo -n "]2;${PS1}]1;${PS1}" ;;
    esac
    case ${_user} in
	root) PS1="${PS1}# " ;;
	*)    PS1="${PS1}\$ " ;;
    esac
}

alias cd='cd_prompt'

-- 
Chris