Current directory in the ksh prompt?
Marc Unangst
mju at mudos.ann-arbor.mi.us
Sun Apr 28 14:01:43 AEST 1991
I wrote:
> I recently started using ksh, and one thing I miss dearly from csh is
> the ability to put the current directory in your prompt. With csh, it
[...]
Well, I've gotten many replies to this question. The general idea is
to create a function called "_cd" (or something similar), which does
the actual cd and then resets the prompt, and then alias cd to this
function. The slickest answer was by Mike O'Connor, who submitted the
following function:
function _cd {
unalias cd
cd $1
alias cd=_cd
if [ "${PWD#${HOME}}" != "${PWD}" ]
then
PS1='"${USER}@${HOSTNAME%%.*}:~/${PWD#${HOME}}> "'
else
PS1='"${USER}@${HOSTNAME%%.*}:${PWD}> "'
fi
}
This cleverly uses the ksh string-substitution features to strip the
trailing domain name off $HOSTNAME, as well as substitute "~/" for the
leading path when the current directory is in or below your home
directory. The "unalias cd; cd $1; alias cd=_cd" part could be
replaced with "\cd $1", I believe; otherwise, this answer is almost
perfect.
Thanks to everybody who replied to this!
--
Marc Unangst |
mju at mudos.ann-arbor.mi.us | "Bus error: passengers dumped"
...!hela!mudos!mju |
More information about the Comp.unix.shell
mailing list