From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Fri, 4 Nov 2005 11:27:25 -0500 From: Russ Cox To: erik quanstrom , Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] tab completion and command history in rc In-Reply-To: <20051104145056.A3EC1651A4@dexter-peak.quanstro.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <436AF189.2080909@lanl.gov> <20051104145056.A3EC1651A4@dexter-peak.quanstro.net> Cc: Topicbox-Message-UUID: a56fcac4-ead0-11e9-9d60-3106f5b1d025 > i looked at modifying rc to write commands to a history file but it > didn't seem to fit very well. maybe a hook would be better as in it's not hard. perhaps you object to rc's reformatting of what you typed? diff -c ./exec.c h/exec.c ./exec.c:9,14 - h/exec.c:9,16 #include "exec.h" #include "io.h" #include "fns.h" + + tree *line; /* * Start executing the given code at the given pc with the given redirect= ion */ ./exec.c:112,118 - h/exec.c:114,120 { =09code bootstrap[32]; =09char num[12], *rcmain; - =09int i; + =09int i, fd; =09 =09/* needed for rcmain later */ =09putenv("PLAN9", unsharp("#9")); ./exec.c:123,128 - h/exec.c:125,132 =09if(flag['I']) flag['i'] =3D 0; =09else if(flag['i']=3D=3D0 && argc=3D=3D1 && Isatty(0)) flag['i'] =3D fl= agset; =09rcmain=3Dflag['m']?flag['m'][0]:Rcmain(); + =09if((fd =3D open("/tmp/history", OWRITE)) >=3D 0) + =09=09history=3Dopenfd(fd); =09err=3Dopenfd(2); =09kinit(); =09Trapinit(); ./exec.c:773,778 - h/exec.c:777,788 =09=09} =09} =09else{ + =09=09if(p->iflag && history && line){ + =09=09=09char buf[30]; + =09=09=09strcpy(buf, ctime(time(0))); + =09=09=09buf[28] =3D 0; + =09=09=09pfmt(history, "%s %t\n", buf, line); + =09=09} =09=09ntrap =3D 0;=09/* avoid double-interrupts during blocked writes */ =09=09--p->pc;=09/* re-execute Xrdcmds after codebuf runs */ =09=09start(codebuf, 1, runq->local); diff -c ./io.h h/io.h ./io.h:11,16 - h/io.h:11,17 =09char *bufp, *ebuf, *strp, buf[NBUF]; }; io *err; + io *history; io *openfd(int), *openstr(void), *opencore(char *, int); int emptybuf(io*); void pchr(io*, int); diff -c ./rc.h h/rc.h ./rc.h:143,145 - h/rc.h:143,146 int lastc; int lastword; int kidpid; + extern tree *line; diff -c ./syn.y h/syn.y ./syn.y:21,28 - h/syn.y:21,28 %type NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN %type WORD REDIR DUP PIPE %% - rc:=09=09=09=09{ return 1;} - |=09line '\n'=09=09{return !compile($1);} + rc:=09=09=09=09{ line =3D nil; return 1;} + |=09line '\n'=09=09{ line =3D $1; return !compile($1);} line:=09cmd |=09cmdsa line=09=09{$$=3Dtree2(';', $1, $2);} body:=09cmd