Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!ptsfa!cpro!asgard From: asgard@cpro.UUCP Newsgroups: net.sources Subject: Prompt wars, revisited. Message-ID: <300@cpro.UUCP> Date: Tue, 24-Mar-87 22:27:24 EST Article-I.D.: cpro.300 Posted: Tue Mar 24 22:27:24 1987 Date-Received: Fri, 27-Mar-87 02:55:13 EST Reply-To: asgard@cpro.UUCP (J.R. Stoner) Distribution: world Organization: CompuPro/VIASYN Corporation Lines: 100 # This posting is an updated version of Ben Cranston's prompt setting # program and aliases. The aliases from cshrc are intended for your # .cshrc file. -----cut here-----cut here-----cut here-----cut here----- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # cshrc # genpro.c # This archive created: Tue Mar 24 19:20:21 1987 export PATH; PATH=/bin:$PATH if test -f 'cshrc' then echo shar: will not over-write existing file "'cshrc'" else sed 's/^ X//' << \SHAR_EOF > 'cshrc' Xalias cd 'cd \!*; set prompt="`genpro`"' Xset prompt="`genpro`" X SHAR_EOF fi # end of overwriting check if test -f 'genpro.c' then echo shar: will not over-write existing file "'genpro.c'" else sed 's/^ X//' << \SHAR_EOF > 'genpro.c' X/* Generate prompt string X * Ben Cranston 3/14/87 X * X * designed to be called as: X * X * alias cd 'cd \!*; set prompt="`dirs|genpro`"' X * X * builds and outputs string: [!] X * X * where is the name of the current host sans trailing domains X * is the current directory, with all but the last two X * directory names replaced by ... for brevity. X * X * I had all this working with "awk" scripts, but it was taking over X * four SECONDS to switch directories. This was considered wasteful. X * X * SYSTEM V version by J.R. Stoner (asgard@cpro.UUCP) 03/24/87 X */ X X#define BUFFSIZE 512 X X#include X Xextern char *getcwd(); Xextern char *strchr(); Xextern char *strrchr(); X Xmain(argc,argv) Xint argc; Xchar **argv; X{ X struct utsname u; X char dirs[BUFFSIZE], buff[BUFFSIZE]; X char *cp; X char *p1, *p2; X uname(&u); X getcwd(dirs,(sizeof dirs) - 2); X if((cp=strchr(dirs,' ')) != (char *)0) X *cp = 0; /* truncate dir string at first space (if any) */ X X/* search backwards for slash. if found, temporarily make null and X * search backwards for slash again. if found again, replace string X * to the left of the second slash with "..." X * X * the additional test of (p1!=dirs) is for a special case, a two-string X * explicitly rooted. that is, "cd /etc/ns" will display as /etc/ns X * rather than ...etc/ns X */ X X buff[0] = 0; X cp = dirs; X if ( 0 != (p2 = strrchr(dirs,'/')) ) { X *p2 = 0; X if ( (0 != (p1 = strrchr(dirs,'/'))) && (p1 != dirs) ) { X strcpy(buff,"..."); X cp = p1 + 1; X } X *p2 = '/'; X } X strcat(buff,cp); X printf("%.8s[!] %s %% ",u.nodename,buff); X} X SHAR_EOF fi # end of overwriting check # End of shell archive exit 0 -- "To prevent having to tell fools to RTFM don't let on you WTFM to begin with." J.R. Stoner asgard@cpro.UUCP asgard@wotan.UUCP P.S. I help CompuPro make computers. They do not help me make my opinions.