In search of a decent prompt

Ben Humphreys cline at pnet01.cts.com
Thu Apr 14 13:16:59 AEST 1988


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 at nosc.mil
INET: cline at pnet01.CTS.COM



More information about the Comp.unix.xenix mailing list