9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Russ Cox <rsc@swtch.com>
To: erik quanstrom <quanstro@speakeasy.net>,
	Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] tab completion and command history in rc
Date: Fri,  4 Nov 2005 11:27:25 -0500	[thread overview]
Message-ID: <ee9e417a0511040827i7f76d805y42199469f12b8c33@mail.gmail.com> (raw)
In-Reply-To: <20051104145056.A3EC1651A4@dexter-peak.quanstro.net>

> 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 redirection
   */
./exec.c:112,118 - h/exec.c:114,120
  {
  	code bootstrap[32];
  	char num[12], *rcmain;
- 	int i;
+ 	int i, fd;
  	
  	/* needed for rcmain later */
  	putenv("PLAN9", unsharp("#9"));
./exec.c:123,128 - h/exec.c:125,132
  	if(flag['I']) flag['i'] = 0;
  	else if(flag['i']==0 && argc==1 && Isatty(0)) flag['i'] = flagset;
  	rcmain=flag['m']?flag['m'][0]:Rcmain();
+ 	if((fd = open("/tmp/history", OWRITE)) >= 0)
+ 		history=openfd(fd);
  	err=openfd(2);
  	kinit();
  	Trapinit();
./exec.c:773,778 - h/exec.c:777,788
  		}
  	}
  	else{
+ 		if(p->iflag && history && line){
+ 			char buf[30];
+ 			strcpy(buf, ctime(time(0)));
+ 			buf[28] = 0;
+ 			pfmt(history, "%s %t\n", buf, line);
+ 		}
  		ntrap = 0;	/* avoid double-interrupts during blocked writes */
  		--p->pc;	/* re-execute Xrdcmds after codebuf runs */
  		start(codebuf, 1, runq->local);
diff -c ./io.h h/io.h
./io.h:11,16 - h/io.h:11,17
  	char *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<tree> NOT FOR IN WHILE IF TWIDDLE BANG SUBSHELL SWITCH FN
  %type<tree> WORD REDIR DUP PIPE
  %%
- rc:				{ return 1;}
- |	line '\n'		{return !compile($1);}
+ rc:				{ line = nil; return 1;}
+ |	line '\n'		{ line = $1; return !compile($1);}
  line:	cmd
  |	cmdsa line		{$$=tree2(';', $1, $2);}
  body:	cmd


  parent reply	other threads:[~2005-11-04 16:27 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04  4:27 YAMANASHI Takeshi
2005-11-04  5:28 ` Ronald G Minnich
2005-11-04  4:41   ` Matthew J. Sottile
2005-11-04  5:26   ` Jack Johnson
2005-11-04  8:50   ` lucio
2005-11-04 15:06   ` erik quanstrom
2005-11-04 15:24     ` Axel Belinfante
2005-11-04 15:29       ` erik quanstrom
2005-11-04 15:26     ` Charles Forsyth
2005-11-04 15:54       ` erik quanstrom
2005-11-05  9:20         ` Charles Forsyth
2005-11-04 16:27     ` Russ Cox [this message]
2005-12-09  1:58       ` erik quanstrom
2005-11-05  8:54     ` Scott Schwartz
2005-11-05 12:13       ` erik quanstrom
2005-11-05 16:01       ` Ronald G Minnich
     [not found] <000201c5e0e5$bbd617f0$14aaa8c0@utelsystems.local>
2005-11-04  6:46 ` Nils O. Selåsdal
  -- strict thread matches above, loose matches on Subject: below --
2005-11-04  4:01 YAMANASHI Takeshi
2005-11-04  3:42 YAMANASHI Takeshi
2005-11-04  3:45 ` Russ Cox
2005-11-04  2:30 YAMANASHI Takeshi
2005-11-04  3:08 ` Russ Cox
2005-11-04  2:01 Federico G. Benavento
2005-11-04  1:29 Federico G. Benavento
2005-11-04  0:59 Rian Hunter
2005-11-04  1:06 ` Uriel
2005-11-04  1:07 ` Russ Cox
2005-11-04  1:14 ` John Floren
2005-11-04  1:22   ` Russ Cox
2005-11-04  1:22   ` Uriel
2005-11-04  1:27     ` Uriel
2005-11-04  2:02       ` Russ Cox
2005-11-04  1:56     ` Rian Hunter
2005-11-04  2:08     ` Skip Tavakkolian
2005-11-04  9:20       ` William Staniewicz
     [not found]     ` <000001c5e0e1$76791f80$14aaa8c0@utelsystems.local>
2005-11-04  6:58       ` Nils O. Selåsdal
2005-11-04  1:23   ` Paul Lalonde
2005-11-04  9:02   ` Scott Schwartz
2005-11-04 15:13   ` "Nils O. Selåsdal"

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee9e417a0511040827i7f76d805y42199469f12b8c33@mail.gmail.com \
    --to=rsc@swtch.com \
    --cc=9fans@cse.psu.edu \
    --cc=quanstro@speakeasy.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).