[comp.unix.xenix.sco] Printing Working Directory in CSH

root@swatty.UUCP (Superuser) (04/27/91)

Question:

Does anybody know how to set the prompt in csh so that the current directory
name (eg., /usr/lib/uucp) is printed (kind of like a dos $p$g), also can this
be done is sh...

Thanx,


Larry

sginn@hlthnt.UUCP (Steve Ginn) (04/28/91)

In article <46@swatty.UUCP> root@swatty.UUCP (Superuser) writes:

   Question:

   Does anybody know how to set the prompt in csh so that the current directory
   name (eg., /usr/lib/uucp) is printed (kind of like a dos $p$g), also can this
   be done is sh...


Try the following in the .cshrc file:

	alias setprompt 'set prompt="`pwd` \\!%> "'
	setprompt

and then comment out the line set prompt=\!%\

Works for me!

Steve Ginn

itkin@mrspoc.Transact.COM (Steven M. List) (04/30/91)

root@swatty.UUCP (Superuser) writes:

>Does anybody know how to set the prompt in csh so that the current directory
>name (eg., /usr/lib/uucp) is printed (kind of like a dos $p$g), also can this
>be done is sh...

Here's how I do it - works quite nicely, and the delay when changing 
directories is minimal:

    set UID = `id | sed 's/uid=\([0-9][0-9]*\).*/\1/'`
    if ($UID == 0) then
        set uname = "`uname -n`-ROOT"
    else
        set uname = `uname -n`
    endif

    alias cd 'chdir \!* ; set prompt = "-${uname}:`pwd`-\! > "'
    cd .

note that the final "cd ." is executed in .cshrc when the alias is set
up so that the prompt will be set the first time.
-- 
 +----------------------------------------------------------------------------+
 :                Steven List @ Transact Software, Inc. :^>~                  :
 :           Chairman, Unify User Group of Northern California                :
 :                         itkin@Transact.COM                                 :

jeffl@comix.UUCP (Jeff Liebermann) (04/30/91)

In article <46@swatty.UUCP> root@swatty.UUCP (Superuser) writes:
>Does anybody know how to set the prompt in csh so that the current directory
>name (eg., /usr/lib/uucp) is printed (kind of like a dos $p$g), also can this
>be done is sh...

For csh, I use:

set	myport = `tty`			# get tty name
setenv	PORT	`basename $myport`	# remove /dev from login port
setenv	LOGNAME	`logname`		# get login name
					# redefine the cd command
alias	cd	'cd \!*; set prompt="[$PORT] [$LOGNAME] `pwd` -> "'
cd					# required to start prompt


For ksh, I use:

LOGNAME=`logname`		# Keep the logname
MACHINE=`uuname -l`		# Get the name of the machine
# MACHINE=`hostname`		# Get the name of the machine
TTY=`tty`			# Name of tty login port
PORT=`basename $TTY`		# Remove the /dev/ part
PS1='[$MACHINE $PORT] [$LOGNAME] $PWD =>  '	# set the main prompt


For sh, I suffer without...

---
# Jeff Liebermann   Box 272   1540 Jackson Ave     Ben Lomond    CA  95005
# (408)336-2558 voice  (408)429-0483 digital pager  wb6ssy  CIS:73557,2074 
# PC REPAIR & RF DESIGN.  Committee Against Double Spacing And Wide Margins.
# jeffl@comix.santa-cruz.ca.us  uunet!comix!jeffl  ucscc.ucsc.edu!comix!jeffl

steve@nshore.ncoast.org (Stephen J. Walick) (05/01/91)

As quoted from <112@comix.UUCP> by jeffl@comix.UUCP (Jeff Liebermann):

+---------------
| In article <46@swatty.UUCP> root@swatty.UUCP (Superuser) writes:
| >Does anybody know how to set the prompt in csh so that the current 
| >directory name (eg., /usr/lib/uucp) is printed (kind of like a
| >dos $p$g), also can this be done in sh...
| 
| For csh, I use:
| 
| For ksh, I use:
| 
| For sh, I suffer without...
+---------------

So far, for 'csh' and 'ksh' users, the question is answered, but some
of us (like myself) do 99% of our work in < /bin/sh > -- can anyone
come up with a solution for us who are somewhat confined to < /bin/sh >,
without having to have to make an alias of something else to change
directories, like `` cdd () { cd $*; ... ; } '' , which does work, but
is a pain in the neck to remember to execute instead of `` cd '', and
does take a bit of processing time??

Thanks to any 'wizards' out there who can come up with an answer to
this one!

-- 

Stephen J. Walick, Asst Sysop of the  < XBBS >  program  at  NCoast.ORG
{uunet|backbone}!ncoast.org!nshore!steve        nshore!steve@ncoast.org

jallen@eeserv1.ic.sunysb.edu (Joseph Allen) (05/05/91)

In article <1991May1.001454.9035@nshore.ncoast.org> steve@nshore.ncoast.org (Stephen J. Walick) writes:
>As quoted from <112@comix.UUCP> by jeffl@comix.UUCP (Jeff Liebermann):
>[how do you make 'sh' show current path whenever you "cd"]

All you have to do is replace all occurances of 'cd' in the shell program
with some new name.  I used my editor to do this, but most editors can't
handle ascii files so I made a simple program to do it.  The new name for the
command I picked is 'ce'.  Originally I tried 'Cd' but that didn't work.  I
think either it doesn't like the command being in uppercase, or the commands
are sorted.  'ce' is in the same sort position as 'cd' and it works.

1) compile this program to 'a.out'

	main()
	{
	int c;
	while(-1!=(c=getchar()))
	 if(c!='c') putchar(c);
	 else
	  {
	  c=getchar();
	  if(c=='d') putchar('c'), putchar('e');
	  else putchar('c'), putchar(c);
	  }
	}

2) Now run the program and make a new shell (it would not be a good idea to
   replace sh)

	cat /bin/sh | a.out >/bin/jsh
	chmod a+x /bin/jsh

   (jsh for Joe's shell, of course :-)

3) now change your shell to the new shell in the password file and put this
   in your .profile

	cd () { ce $*; PS1=`pwd`">"; }
	cd
-- 
/*  jallen@ic.sunysb.edu  */     /* Amazing */     /* Joe Allen 129.49.12.74 */
int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
+r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p<1659?79:0:p>158?-79:0,q?!a[p+q*2
]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}

carl@p4tustin.UUCP (Carl W. Bergerson) (05/10/91)

sginn@hlthnt.UUCP (Steve Ginn) writes:
>In article <46@swatty.UUCP> root@swatty.UUCP (Superuser) writes:
>  Question:
>  Does anybody know how to set the prompt in csh so that the current directory
> 
>Try the following in the .cshrc file:
> 
> alias setprompt 'set prompt="`pwd` \\!%> "'
> setprompt

Don't forget to alias cd so that it calls setprompt after the cd.

If I remember correctly this subject was addressed in Unix World,
probably the Wizards Grabbag column, in the last quarter or half of 1989.
There might be an answer for sh there.

Carl
-- 
Carl Bergerson                                           uunet!p4tustin!carl  
Point 4 Data Corporation                                     carl@point4.com
15442 Del Amo Avenue                                   Voice: (714) 259 0777
Tustin, CA 92680-6445                                    Fax: (714) 259 0921