cline@pnet01.cts.com (Ben Humphreys) (04/14/88)
In search of the perfect prompt... Under DOS, I have quite a nice prompt. It's colorful yet functional. It displays the current path ($G) surrounded by brackets in bright white. It then sends the ANSI escape sequence for green so that all DOS I/O is in green. I've recently gotton into XENIX also. When the system came back with the bland '% ' in csh, I thought, what a week operating system. So, about the past month, on and off, I have been working on my prompt project. This is what I have come up with. The following program, color is called from .cshrc /* Program ........ color.c Updated ........ 11 April 1988 Purpose ........ Send ANSI escape sequences for color */ #include <stdio.h> /* printf() */ #include <string.h> /* strcmp() */ #define ESC 0x1b main(argc, argv) int argc; char *argv[]; { char *p, *getenv(); p = getenv("TERM"); if (strcmp(p, "ansi") == 0) { if (*argv[1] == '1') { printf("%c[2;15;0m", ESC); printf("["); printf("%c[2;14;0m", ESC); } if (*argv[1] == '2') { printf("%c[2;15;0m", ESC); printf("]"); printf("%c[2;2;0m", ESC); } } if (strcmp(p, "wy60") == 0) { if (*argv[1] == '1') printf("["); if (*argv[1] == '2') printf("]"); } } Here is my .cshrc file # Commands here are executed each time csh starts up. # setenv SHELL /bin/csh # default shell location setenv MODEM /dev/tty11 # used by xcomm program set noclobber # don't allow '>' to overwrite set history = 20 # save last 20 commands set term = (`tset -m ansi:ansi -m :\?wy60 -r -S -Q`) set path = (. /bin /etc /usr/bin /usr/bin2 /usr/fox) setenv TERM $term[1] # environment variable TERM set c1 = "`color 1` " # beginning chunk of prompt set c2 = "`color 2` " # ending chunk of prompt set me = "`logname`" # login name set prompt = "$c1$me #! - `pwd` $c2" # set the rad prompt alias del 'mv \!* /tmp' # do not use rm, use del for safty alias cd 'cd \!*; set prompt = "$c1$me #! - `pwd` $c2"' alias xcomm 'xcomm b7 2400' # automatically set xcomm defaults The terminal type is set by tset, normally ansi but sometimes I logon under a Wyse 60 which doesn't support color (or ANSI escape sequences). The environment variable TERM is set to the terminal type being used. c1 gets set to the output of the above program (color.c) when called with a parameter of 1. This is the left bracket in bright white plus an escape sequence for bright yellow for ansi or a mere bracket ([) for wy60. c2 gets set to the output of color when called with a parameter of 2. This is a bright white escape code plus a bracket plus a green escape code for ansi or just a right bracket plus a space for wy60. The following line sets the initial prompt using those two variables and the "me" variable. As the prompt has the current directory embedded in it, this will need to be updated when the directory is changed. That's why I aliased cd. While this is not perfect (does not take into account pushd and popd and I'm sure others), it works for my purposes. I hope others can benefit from my experience; god knows it took me long enough to figure out how to do this. UUCP: {cbosgd, hplabs!hp-sdd, sdcsvax, nosc}!crash!pnet01!cline ARPA: crash!pnet01!cline@nosc.mil INET: cline@pnet01.CTS.COM
mike@ivory.SanDiego.NCR.COM (Michael Lodman) (04/15/88)
On this subject, the following is a prompt I developed for my system based on one somebody else did under DOS. Place the following lines in your .cshrc, replacing # with ^[. #begin set sysname=`uname -n` set day=`date '+%a %h %d , 19%y'` alias cd 'cd \!* ; set prompt="#7#[0m#[3m#[2;15;4m#[H#[K#[12m]#[10m#[12C$day#[10C${sysname}:`pwd`#[1;80H#[12m]#[10m#8#[2;15;1m\\!>#[0m#[2;15;1m#[1C"' cd . #end To get a ^[ into a file, type the following: % echo "<esc>" >> Filename The colors may be modified based on the documentation for screen in the Xenix manuals. If you need help, email me or call at the below number. -- Michael Lodman (619) 485-3335 Advanced Development NCR Corporation E&M San Diego mike.lodman@ivory.SanDiego.NCR.COM {sdcsvax,cbatt,dcdwest,nosc.ARPA,ihnp4}!ncr-sd!ivory!mike When you die, if you've been very, very good, you'll go to ... Montana.