Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!umich!sharkey!rjf001!mudos!mju From: mju@mudos.ann-arbor.mi.us (Marc Unangst) Newsgroups: comp.unix.shell Subject: Re: Current directory in the ksh prompt? Message-ID: Date: 28 Apr 91 04:01:43 GMT References: Organization: The Programmer's Pit Stop, +1 313 665 2832 Lines: 36 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@mudos.ann-arbor.mi.us | "Bus error: passengers dumped" ...!hela!mudos!mju |