[comp.unix.shell] How to put something on Status line

dickson@felix.UUCP (Pete Dickson) (11/01/90)

Ok....I've tried everything.

I put this line into my .login file (and just about every imaginable c
combination)

echo '[1;24r[23;1H[7mYou are in ... '{pwd}'[0m'
       ^^^^^^^^^^^     ^^^                  ^^^    
          |           (rev video,ok)         |    
          |                              to print working directory
     to print on status line                (doesn't work right)
       (doesn't work right)

perhaps it's something to do with the vt100 configuration, BUT, the termcap
lists a vt100-s-bot configuration which I have set. (for bottom status line)
when I have that set, then a program like sysline WORKS. 

The result of the above mess is I get this message right before my regular
prompt appears "You are in ... pwd"

I also tried this, to see if I could just keep my working directory as part
of the prompt itself.

set prompt = '[7m[1m'{pwd}'\![0m-=->'

the result (in rev video)

pwd1-=->

or 

set prompt = '^[[7m^[[1m'${cwd}'\!^[[0m-=->'

which results in (in rev video)

d/dickson1-=->

Excellent! Just what I wanted, the only problem is, when I CHANGE directories,
the prompt stays the same. I want it to show the directory I'm in!

Please tell me you can help Mr. Wizard!

Thanks!

Pete

Oh, BTW this is in csh
--
-------------------------------------------------------------------------------
I WON'T sign! You can't make me! I won't, I WON'T!! ok here. dickson@felix.UUCP
-------------------------------------------------------------------------------

rbr@bonnie.ATT.COM (4197,ATTT) (11/02/90)

Bob Rager

-------------------- CUT HERE ---------------------
/* cc -O -s -o ${HOME}/bin/time_line timeline.c -lcurses  */

/* Name:	time_line
**
** INVOCATION:	time_line [-d] [-m]
**
** DESCRIPTION:
**
**	"time_line" is a program to print the current date and time
**	on the 25'th line - status line - of terminals that have that
**	capability. If "time_line" is called and the terminal does not
**	have a status line capability, the program exits gracefully.
**	Otherwise, the status line is cleared and the date (mm/dd) time
**	(hh:mm) is printed on the status line. The time is updated every
**	minute. Also the MAILPATH environment variable is accessed on each
**	cycle to determine if you have mail. The first time mail is detected
**	the message "MAIL" is appended to the date and time. The next cycle
**	the message "mail" is appended. When you process the mail, the message
**	disappears on the next cycle.
**
**	The program illustrates the use of curses control of the cursor to
**	print on the 25'th line; and to replace the cursor for the user.
**
**	Note that the program forks a child process after supressing interupt
**	and lets the parent process die. This is the way to do the UNIX
**	equivalent of an MSDOS TSR. The child stays in the system as an
**	orphaned process but supressing SIGINT and SIGQUIT keeps the system
**	from eventually killing the process. SIGHUP (hangup) kills the process
**	but allows the process to clean up before leaving.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/signal.h>
#include <time.h>
#include <fcntl.h>

/* Global variables */
char to_status_line[80];
char from_status_line[80];
char dis_status_line[80];
char clr_eol[100];
char rev_out[20];
char rev_end[20];
int eslok, columns ;
int quiet = 0;
int mail = 1;
int debug = 0;
short uid, pid, lpid;
void clr_status_line();

/* Global Functions */
outc(c) char c; { putchar(c);} 

main(argc, argv)
	int argc;
	char *argv[];
{
	int c, i;
	struct tm *tm, *localtime();
	time_t now, tenmin;
	char msg[BUFSIZ], *p, *host, *strchr();
	char *mfile, *getenv();
	struct stat new_st, old_st;

	void (*status_fmt)();
	void prt_status_line(), ctrm_status();

	extern char *optarg;
	extern int optind;

	FILE *fp = NULL;

	signal(SIGINT,SIG_IGN);
	signal(SIGQUIT,SIG_IGN);
	signal(SIGHUP,clr_status_line);
	signal(SIGTERM,clr_status_line);
	status_fmt = prt_status_line;
	while((c = getopt(argc, argv, "cdm")) != EOF) {
		switch(c) {
		case 'd':
			debug = 1 ;
			signal(SIGINT, clr_status_line);
			signal(SIGQUIT, SIG_DFL);
			break;
		case 'm':
			mail = 0 ;
			break;
		default:
			exit(1);
			break;
		}
	}
	initterm();
	/* This will allow starting from .profile         */
	/* immediately fork and let the parent die */
	if(!debug) {
		switch(fork()) {

		case -1:	/* fork failed */
			perror("fork");
			exit(1);

		case  0:	/* child */
			break;

		default:	/* parent dies */
			exit(0);
			break;
		}
	}
	uid= getuid();
	pid= getpid();
	mfile = getenv("MAIL");
	if( debug ) printf("%s\n", mfile);
	close(0);
	close(1);
	fcntl(2, F_DUPFD, 1);
	if(stat(mfile, &old_st) < 0) {
		old_st.st_mtime = 0;
		old_st.st_atime = 0;
	}
 while( 1 ){
	time(&now);
	tm = localtime(&now);
	sprintf(msg, "%d/%d %d:%02d ",
		tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min);
	tenmin = now - (10*60);
	if( mail ){
		if(stat(mfile, &new_st) >= 0) {
			if((new_st.st_size > 0)
			&& (new_st.st_mtime > new_st.st_atime)) {
				if(new_st.st_mtime > old_st.st_mtime) {
					putc('\007', stdout);
					strcat(msg, "  MAIL");
				} else {
					strcat(msg, "  mail");
				}
			}
			old_st = new_st;
		}
	}
	(*status_fmt)(msg);
 	sleep(60 - (now%60));
    }
}

void
prt_status_line(msg)
char *msg;
{
	int adj = 0;
 	tputs(tparm(to_status_line, 0), 1, outc);
	tputs(clr_eol, 1, outc);
	tputs(from_status_line, 1, outc);
	fflush(stdout);
 	tputs(tparm(to_status_line, 0), 1, outc);
	tputs(msg, 1, outc);
	tputs(from_status_line, 1, outc);
	fflush(stdout);
}
void
clr_status_line()
{
	printf("%s%s%s%s",
		tparm(to_status_line, 0),
		clr_eol,
		from_status_line,
		dis_status_line);
	fflush(stdout);
	exit(0);
}
initterm() {
	char *term, cp[256], *r, *tgetstr();
	char tbuf[2*1024];

	if ((term=getenv("TERM")) == NULL) {
		if (!quiet)
			fprintf(stderr, "sysline: No TERM variable in enviroment\n");
		exit(1);
	}
	if (tgetent(tbuf, term) <= 0) {
		if (!quiet)
			fprintf(stderr, "sysline: Unknown terminal type: %s\n", term);
		exit(1);
	}
	if (tgetflag("hs") <= 0) {
		if (!quiet)
			fprintf(stderr, "sysline: No status capability for %s\n", term);
		exit(1);
	}

	if(r = tgetstr("i1", cp)) {
		tputs(r, 1, outc);
	}
	if(r = tgetstr("is", cp)) {
		tputs(r, 1, outc);
	}
	if(r = tgetstr("i3", cp)) {
		tputs(r, 1, outc);
	}
	fflush(stdout);

	/* the "-1" below is to avoid cursor wraparound problems */
	if((columns=tgetnum("ws")) <= 0) { /* special width of status line */
		columns = tgetnum("co");
	}
	columns -= 1;
	if(r = tgetstr("ts", cp)) {
		strcpy(to_status_line, r);
	}
	if(r = tgetstr("fs", cp)) {
		strcpy(from_status_line, r);
	}
	if(r = tgetstr("ds", cp)) {
		strcpy(dis_status_line, r);
	}
	eslok = tgetflag("es");
	if(eslok) {
		if(r = tgetstr("ce", cp)) {
			strcpy(clr_eol, r);
		}
		if(r = tgetstr("so", cp)) {
			strcpy(rev_out, r);
		}
		if(r = tgetstr("se", cp)) {
			strcpy(rev_end, r);
		}
	} else {
		int i;
		for(i=0;i < columns ; i++) clr_eol[i] = ' ';
		strcpy(rev_out,"");
		strcpy(rev_end,"");
	}
}
------------------------ END OF C SOURCE ----------------------

rbr@bonnie.ATT.COM (4197,ATTT) (11/02/90)

Sorry, the text got lost on the last posting. The program is a highly
stripped verion of "sysline".  I wrote this as an exercise to learn some
curses.  I have tried all kinds of shell echo tricks to use the status
line on my ATT 4425 without success.  This program does the job. Putting
the CWD on the stat line is a good idea, its clumsy on the prompt.

Bob Rager

rlp@druwa.ATT.COM (PrehnRL) (11/03/90)

In article <1990Nov2.144633.10734@cbnewsl.att.com>, rbr@bonnie.ATT.COM (4197,ATTT) writes:
> Sorry, the text got lost on the last posting. The program is a highly
> stripped verion of "sysline".  I wrote this as an exercise to learn some
> curses.  I have tried all kinds of shell echo tricks to use the status
> line on my ATT 4425 without success.  This program does the job. Putting
> the CWD on the stat line is a good idea, its clumsy on the prompt.
> 
> Bob Rager


if you put the following function in a file (e.g. set4d)
#--------------------------
	_cd()
		{
		\cd "$@"
		DIR=`pwd`
		echo "\033\067\033[25;9H ${DIR}                                           \033\070\c"
		}
#--------------------------
and in your .kshrc file:
#--------------------------
	alias cd=_cd
	. set4d
#--------------------------
You will get the current directory on the status line.


While I'm at it, the following script works for the AT&T ctrm
HP2621 terminal emulator:
#--------------------------
	_cd()
		{
		\cd "$@"
		X=`echo "                                        $PWD"\
		|cut -c$((${#PWD}/2))-$((40+${#PWD}))`
		echo "\033&P10 2$X\000\c"
		unset X
		}
#--------------------------

Lastly for AT&T 630 terminals
#--------------------------
	_cd()
		{
		\cd "$@"
		DIR=`pwd`
		SIZE=`expr "${DIR}" : '.*'`
		echo "\033[?${SIZE};2v${DIR}\c"
		}
#--------------------------

 Robert Prehn      +-----------------------------------------------------------+
 AT&T Bell Labs    |     ____   _______   _____   _______                      |
 Room  1F50        |    / __ \ |__   __| /   _ \ |__   __|                     |
 11900 North Pecos |   | <__> |   | |    \  \ \_\   | |                        |
 Denver, Co  80234 |   |  __  |   | |    /   \ __   | |    THE           CHOICE|
        	   |   | |  | |   | |   |  (\ / /   | |                        |
 drutx!rlp         |   |_|  |_|   |_|    \_____/    |_|                        |
 (303) 538-4554    |                                                           |
                   +-----------------------------------------------------------+

dcon@cbnewsc.att.com (david.r.connet) (11/07/90)

In article <6517@drutx.ATT.COM>, rlp@druwa.ATT.COM (PrehnRL) writes:
> #--------------------------
> Lastly for AT&T 630 terminals
> #--------------------------
> 	_cd()
> 		{
> 		\cd "$@"
> 		DIR=`pwd`
> 		SIZE=`expr "${DIR}" : '.*'`
> 		echo "\033[?${SIZE};2v${DIR}\c"
> 		}
> #--------------------------

This is good for a cd command, but be careful about generalizing to
putting anything in the 630 header.  expr will report 10 as the
length of "word\tword".  echo produces 9.  Interesting results can
result in the header.

Also the '2' in '2v' in the echo sequence can be:
	0: left justify
	1: center
	2: right justify

Dave Connet
dcon@iwtng.att.com