Path: utzoo!attcan!uunet!husc6!mailrus!ames!umd5!mimsy!aplcen!anagld!rcsmith
From: rcsmith@anagld.UUCP (Ray Smith)
Newsgroups: comp.sources.d
Subject: Re: csh prompts
Message-ID: <447@anagld.UUCP>
Date: 23 Jun 88 14:05:31 GMT
References: 
Reply-To: rcsmith@anagld.UUCP (Ray Smith)
Organization: Analytics, Inc., Columbia, MD
Lines: 95

In article  jl42+@psuvax1.UUCP (Jay Mathew Libove) writes:
>Two cshell prompt ideas have been posted to comp.sources.misc in the
>past week or so, so I thought I'd relate a funny reality about cshell
>prompts...
>
>On some systems, specifically those that are huge remote file
>systems (like that of the andrew project at Carnegie Mellon
>University) paths occasionally get like:
>
>/afs/cs.cmu.edu/bsd4.3/ibm032/omega/usr/misc/.X11tra/lib/awm/bitmaps
>
>and since my prompt is (quite similarly to one of the ones just
>posted)
>
>machinename/path(linenumber)
>
>that directory gives me this path for example:
>
>MISTERDATA/afs/cs.cmu.edu/bsd4.3/ibm032/omega/usr/misc/.X11tra/lib/awm/bitmaps:(120) %
>
		

  I wrote a little tool some time back that helps with the extra long
path prompt problem. What it basically does is return the last few
directories of a long prompt up to TOO_LONG characters or the last
directory entry no matter how long it is. I put it as part of my "cd" alias
in .cshrc as follows:

alias cd 'set old=$cwd; chdir \!*;\  (Line broken here due to length limits)
set prompt="`short.prompt $cwd` ($USER - $HOST) $LEVEL-> "'

  An example of how this looks follows:
/usr1/rcsmith (rcsmith - anagld)->  cd source
~/rcsmith/source (rcsmith - anagld)-> cd tools
~/source/tools (rcsmith - anagld)->

  The code ain't real pretty and I haven't investigated it for making it
faster or anything.  I am sure someone will find ways to enhance it.  It
is just a quick little tool I threw together.  In fact it took longer to
add all the comments so that I could post it than it took to write.

  If I should have put it in a 'shar' with all types of docs and stuff I
apologize, I just thought some body could use it.

Enjoy,
Ray

---------------------------Cut here----------------------------------------
#define TOO_LONG 15                          /* HOW MUCH TO BE PRINTED   */
#include 
main(argc,argv)
int argc;
char **argv;
{
	int i, j;                            /* DECLARE SOME COUNTERS    */
	char *cp;                            /* AND A POINTER            */

	*argv++;                             /* INCREMENT ARGV SO THAT IT  */
	cp = *argv;                          /* POINTS TO THE PATH AND SET */
					     /* THE OTHER POINTER          */

	if (*argv == '\0')                   /* IF THERE IS NO ARGUMENT    */
		return (-1);                 /* JUST GET OUT - ABNORMAL EXIT*/
	else
		i = strlen (*argv);          /* SEE HOW LONG THE ARG IS    */

	if (i > TOO_LONG) {                  /* IF THE LENGTH IS TOO LONG  */
		for (j=0; j < i; j++) {      /* FIDDLE WITH THE COUNTERS & */
			if (i-j > TOO_LONG) {   /* POINTER TO SET IT FOR AT*/
				*cp++;       /* LEAST too_long CHARACTERS  */
			}
		}
		while (*cp != '/' && *cp != '\0') /* FIND THE LAST SLASH OR*/
			*cp++;                    /* THE END               */

		if (*cp == '\0') {           /* IF WE ARE AT THE END WE NEED*/
			while (*cp != '/')   /* TO BACK UP TILL WE FIND THE*/
				*cp--;       /* LAST SLASH                 */
		}
		if (strcmp (cp, argv) != 0)  /* IF THEY DON'T POINT TO THE */
			printf ("~");        /* THING WE PRINT A '~' TO    */
					     /* INDICATE MORE              */
	}
	printf ("%s", cp);                   /* NOW PRINT THE STRING       */
}
---------------------------Cut here----------------------------------------
-- 
Ray Smith       | USnail: Suite 200, 9891 Broken Land Pky, Columbia, MD 21046
Analytics, Inc. | GEnie : rcsmith
(301) 381-4300  | CIS   : 72000,1111
		| Net   : ...!uunet!mimsy!aplcen!anagld!rcsmith
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"The trouble with doing something right the first time is that nobody
appreciates how difficult it was." -Walt West
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=