what i find i can't live without is a record
of the commands i've typed.  sometimes a
one-liner from last week is useful.  i use the
commands - and -- (source: /n/sources/contrib/quanstro/src/history.c)
along with the following patch to rc to make it
go.

- erik

; 9diff fns.h
/n/sources/plan9//sys/src/cmd/rc/fns.h:61,66 - fns.h:61,67
  void  start(code*, int, var*);
  int   truestatus(void);
  void  usage(char*);
+ void whistory(tree*);
  int   wordchr(int);
  void  yyerror(char*);
  int   yylex(void);
; 9diff *.y
post...
/n/sources/plan9//sys/src/cmd/rc/syn.y:12,17 - syn.y:12,28
  %{
  #include "rc.h"
  #include "fns.h"
+ 
+ int
+ hcompile(tree *t)
+ {
+       int i;
+ 
+       if(i = compile(t))
+               whistory(t);
+       return !i;
+ }
+ 
  %}
  %union{
        struct tree *tree;
/n/sources/plan9//sys/src/cmd/rc/syn.y:22,28 - syn.y:33,39
  %type<tree> WORD REDIR DUP PIPE
  %%
  rc:                           { return 1;}
- |     line '\n'               {return !compile($1);}
+ |     line '\n'                       { return hcompile($1); }
  line: cmd
  |     cmdsa line              {$$=tree2(';', $1, $2);}
  body: cmd
; cat history.c
#include "rc.h"
#include "exec.h"
#include "fns.h"
#include "io.h"

void
whistory(tree *t){
        char* s;
        int fd, flags;
        io* o;
        var* v;

        if(!runq->iflag || !t)
                return;
        v = vlook("history");
        if(!v->val || count(v->val) != 1)
                return;
        if(v->fn)
                return; /* fn history {echo $*>>$history_file} ? */

        s = v->val->word;
        flags = OWRITE;
        if((fd=open(s, flags))<0 && (fd=create(s, flags, DMAPPEND|0666L))<0){
                /* setvar("history", 0); */
                return;
        }
        
        o = openfd(fd);
        seek(fd, 0, 2);
        pfmt(o, "%t\n", t);
        closeio(o);
}

Reply via email to