[net.unix-wizards] PS1 change

jpage@rruxe.UUCP (J. H. Page) (03/16/85)

Subject: ksh PS1
Newsgroups: net.unix-wizards

any unix-wizards out in net.land know how to have one's UNIX prompt change
to reflect a change in one's working directory.

i have access to sh and ksh on our system.

i know the csh alias command(s) but have had no success translating them
into ksh.


thanks in advance,

jim page

gam@amdahl.UUCP (G A Moffett) (03/19/85)

Ksh has been modified here to translate a '@' in PS1 to the
current working directory.  ('@@' translates to '@').  Apparently
this was the only solution to get $PWD in the prompt.

Anyone for a de-facto standard .... ?
-- 
Gordon A. Moffett		...!{ihnp4,hplabs,sun}!amdahl!gam

mike@whuxl.UUCP (BALDWIN) (03/21/85)

If you want the cwd in the prompt, just make a new function called, say, ch:

ch()
{
	if cd $1
	then PS1="[`pwd`] "
	fi
}

This will work in SVR2 sh as well as ksh.  I see no reason why the shell
has to be modified at all.  We don't need to add any extra baggage to the
shell.  For instance, why is there $PWD in ksh and $cwd in csh?  Doesn't
`pwd` do the same without adding another funny variable to the shell?

							Michael Baldwin
							AT&T Bell Labs
							harpo!whuxl!mike

hansen@pegasus.UUCP (Tony L. Hansen) (03/23/85)

<< how do you get the current directory in the prompt?
<<
< If you want the cwd in the prompt, just make a new function called, say, ch:
< 
< ch()
< {
< 	if cd $1;then PS1="[`pwd`] ";fi
< }

This of course requires you to use the name "ch" instead of "cd" to change
directories. More thorough would be to do the following:

	alias cd=__cd _cd=cd
	function __cd { _cd $*;PS1="[$PWD] "; }

Even better is to do just:

	PWD='[$PWD] '

and not modify cd at all. This will work in the most recent versions of ksh.

< This will work in SVR2 sh as well as ksh.

Neither of the above two solutions will work in the SVr2 sh. I don't know if
the version of ksh available outside of AT&T supports the second solution.

					Tony Hansen
					pegasus!hansen

robert@gitpyr.UUCP (Robert Viduya) (03/23/85)

> If you want the cwd in the prompt, just make a new function called, say, ch:
> 
> ch()
> {
> 	if cd $1
> 	then PS1="[`pwd`] "
> 	fi
> }
> 
The problem with this is that if you're used to the "cd" command, you have
to spend some time acclimating to the new "ch" command.  Your prompt can
lie if you call "cd" directly (without going through "ch").

			robert
-- 
Robert Viduya
Georgia Institute of Technology

...!{akgua,allegra,amd,hplabs,ihnp4,masscomp,ut-ngp}!gatech!gitpyr!robert
...!{rlgvax,sb1,uf-cgrl,unmvax,ut-sally}!gatech!gitpyr!robert

dwight@timeinc.UUCP (Dwight Ernest) (03/24/85)

We don't have ksh, but I have used it while guesting at other
sites. The following used to be part of my .env file under
ksh while I was guesting, and it worked beautifully:

alias lo="off"
function nd {
ldpwd=`pwd`
cd $1 $2 >/dev/null
LDPWD=$ldpwd
PS1="
(! $UNAME `pwd`)
\$>"
PS2="
(! $UNAME `pwd`)
\$\$>"
PS3="
(! $UNAME `pwd`)
select one>"
	;}
alias cd=nd

Note the last alias. I has to follow immediately after the function
definition ends. Also note that my .profile set UNAME=`uname -n`.
And note also that this was System 5 Release 2.0. So my prompt
would appear as:

(32 sysname /current/working/directory)
$>

Where '32' is an example command number from the .history file.
I included sysname from uname in my prompt because I had logins
in so many different systems at the time.

This way, you just use 'cd' like you always did, and, "voila!"