Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rutgers!modus!gear!cadlab!martelli From: martelli@cadlab.sublink.ORG (Alex Martelli) Newsgroups: comp.unix.aix Subject: Re: How To: set PS1 to show users "current" directory? Keywords: AIX Message-ID: <797@cadlab.sublink.ORG> Date: 26 Apr 91 16:51:14 GMT References: <1599@msa3b.UUCP> <6657@awdprime.UUCP> <1991Apr16.093733.19362@ioe.lon.ac.uk> <1991Apr17.144920.17478@grasp1.univ-lyon1.fr> Organization: CAD.LAB, Bologna, Italia Lines: 52 rol@grasp1.univ-lyon1.fr (Paul Rolland) writes: ... : That works fine, but I'd like to have the working directory relative :to my HOME directory. That's is : my HOME is /u/rol. If I'm in /u/rol/tmp/c, :I'd like to have the prompt being tmp/c, or even better, HOME/tmp/c when I'm :in /u/rol/tmp/c and /u when I'm in /u... This is my approach in ksh (in the file that's in envir. var ENV): ---start cut: tradir() { echo $* | sed -e 's,^'$HOME',~,' -f $HOME/.dirsed } dirnam() { if [ -r .dirnam ] then cat .dirnam else tradir $PWD fi } setpro() { export PS1="${LOGNAME}_$THOST `dirnam` [!] " } mycd() { 'cd' $*; setpro } alias cd=mycd ---end cut and in $HOME/.dirsed, I have: ---start cut s,^/\([a-z0-9]*\)root/,\1:, ---end cut That's a bit elaborate, but I like it! If a directory contains a file named .dirnam, then the contents of that file are to be displayed as the name of the directory; else, a leading instance of the user's home directory, if any, is translated to tilde, then sed is passed a user's personalized editing script for directories-in-prompt, which in my case just translates 'root' into ':' if the leading directory is a child of / and its name ends with 'root' (that's because we nfs-mount pippo:/ as /pipporoot...). setpro is a separate shell function because it can be used not only after a cd but also after a push-directory, pop-directory, etc. I'm not using the ksh's option to just expand a variable such as ${PWD} in the prompt, because I want to do (potentially) rather sophisticated editing, which can be a bit costly, and I want to pay that cost only at a cd rather than over and over again! -- Alex Martelli - CAD.LAB s.p.a., v. Stalingrado 53, Bologna, Italia Email: (work:) martelli@cadlab.sublink.org, (home:) alex@am.sublink.org Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; Fax: ++39 (51) 366964 (work only), Fidonet: 332/401.3 (home only).