asgard@cpro.UUCP (03/25/87)
# 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: <hostname> [!] <workdir> X * X * where <hostname> is the name of the current host sans trailing domains X * <workdir> 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 <sys/utsname.h> 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.
zben@umd5.UUCP (03/31/87)
This is what I am using now: alias set_prompt 'set prompt="${hostname}[\\!] `dirs|sed -e '\''s| .*||'\'' -e '\''s|.*[^/]\(/[^/]*/[^/]*\)|...\1|'\''` % "' set hostname=`hostname | sed -e 's/\..*//'` alias cd 'cd \!*; set_prompt' alias pushd 'pushd \!*; set_prompt' alias popd 'popd \!*; set_prompt' set_prompt I refuse to do a "shar" for a six line posting... -- umd5.UUCP <= {seismo!mimsy,ihnp4!rlgvax}!cvl!umd5!zben Ben Cranston zben @ umd2.UMD.EDU Kingdom of Merryland UniSys 1100/92 umd2.BITNET "via HASP with RSCS"
sbb@esquire.UUCP (04/01/87)
In article <1500@umd5.umd.edu> zben@umd5.umd.edu (Ben Cranston) writes: >This is what I am using now: > > alias set_prompt 'set prompt="${hostname}[\\!] `dirs|sed -e '\''s| .*||'\'' -e '\''s|.*[^/]\(/[^/]*/[^/]*\)|...\1|'\''` % "' > set hostname=`hostname | sed -e 's/\..*//'` > alias cd 'cd \!*; set_prompt' > alias pushd 'pushd \!*; set_prompt' > alias popd 'popd \!*; set_prompt' > set_prompt But what about us poor Korn Shell users? Any ideas?
simpson@trwrb.UUCP (04/02/87)
Here are an implementation of pushd and popd in the Korn shell that I put in a file .kshrc. I also use sysline(1) and put the prompt in the bottom of the terminal screen by writing to the .who file. dirstack= function chdir { integer cutoff \cd $@ || return 1 let cutoff="${#HOME} + 1" if [ "`pwd | colrm $cutoff`" = ~ ]; then echo \~`pwd | colrm 1 ${#HOME}` > ~/.who # .who is read by sysline(1) else pwd > ~/.who fi } alias cd=chdir alias back='chdir -' function pushd { integer cutoff if [ $# -ne 1 ]; then return 1 fi chdir $1 || return 1 let cutoff="${#HOME} + 1" dirstack="$OLDPWD $dirstack" for i in `pwd` $dirstack; do if [ "`echo $i | colrm $cutoff`" = ~ ]; then echo -n "~`echo $i | colrm 1 ${#HOME}` " else echo -n "$i " fi done echo } function popd { integer cutoff if [ $# -ne 0 ]; then return 1 fi set -- $dirstack if [ $# -le 0 ]; then echo Directory stack empty return 1 fi chdir $1 || return 1 let cutoff="${#HOME} + 1" shift dirstack=$* if [ "`pwd | colrm $cutoff`" = ~ ]; then echo \~`pwd | colrm 1 ${#HOME}` else pwd fi } function dirs { integer cutoff let cutoff="${#HOME} + 1" for i in `pwd` $dirstack; do if [ "`echo $i | colrm $cutoff`" = ~ ]; then echo -n "~`echo $i | colrm 1 ${#HOME}` " else echo -n "$i " fi done echo } This file gets read on Korn shell invocation by putting the lines ENV=~/.kshrc export ENV . $ENV in my .profile. I also add the lines echo \~ > .who sysline -Dqj to invoke sysline in my .profile. -- Scott Simpson TRW Electronics and Defense Sector ...{decvax,ihnp4,ucbvax}!trwrb!simpson