diff --git a/sys/man/1/sam b/sys/man/1/sam index 1ecb55ede..f9e9afdac 100644 --- a/sys/man/1/sam +++ b/sys/man/1/sam @@ -496,11 +496,20 @@ Plan 9 command. Send the range to the standard input of the Plan 9 command. .TP +.BI ^ " Plan 9-command +Send the standard output of the Plan 9 command +to the command window. +.TP .BI | " Plan 9-command Send the range to the standard input, and replace it by the standard output, of the Plan 9 command. .TP +.BI _ " Plan 9-command +Send the range to the standard input, and send the +standard output of the Plan 9 command to the command +window. +.TP .BI \*a! " Plan 9-command Run the Plan 9 command. @@ -515,6 +524,8 @@ is used. In any of .BR < , .BR > , +.BR ^ , +.BR _ , .B | or .BR ! , diff --git a/sys/src/cmd/sam/cmd.c b/sys/src/cmd/sam/cmd.c index a0e336f01..6e8efa094 100644 --- a/sys/src/cmd/sam/cmd.c +++ b/sys/src/cmd/sam/cmd.c @@ -35,6 +35,8 @@ Cmdtab cmdtab[]={ '>', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, '<', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, '|', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, + '^', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, + '_', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, '=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd, 'c'|0x100,0, 0, 0, 0, aNo, 0, wordx, cd_cmd, 0, 0, 0, 0, 0, 0, 0, 0, @@ -76,7 +78,13 @@ inputc(void) Again: nbuf = 0; - if(downloaded){ + if(cmdbufpos > cmdbuf.nc && cmdbuf.nc > 0){ + cmdbufpos = 0; + bufreset(&cmdbuf); + } + if(cmdbufpos < cmdbuf.nc && cmdbuf.nc > 0) + bufread(&cmdbuf, cmdbufpos++, &r, 1); + else if(downloaded){ while(termoutp == terminp){ cmdupdate(); if(patset) diff --git a/sys/src/cmd/sam/sam.h b/sys/src/cmd/sam/sam.h index a5ff1b9a2..f1cbd8ac0 100644 --- a/sys/src/cmd/sam/sam.h +++ b/sys/src/cmd/sam/sam.h @@ -361,6 +361,8 @@ extern int quitok; extern Address addr; extern Buffer snarfbuf; extern Buffer plan9buf; +extern Buffer cmdbuf; +extern int cmdbufpos; extern List file; extern List tempfile; extern File *cmd; diff --git a/sys/src/cmd/sam/shell.c b/sys/src/cmd/sam/shell.c index fe9162fc6..c0eced359 100644 --- a/sys/src/cmd/sam/shell.c +++ b/sys/src/cmd/sam/shell.c @@ -7,6 +7,8 @@ char errfile[64]; String plan9cmd; /* null terminated */ Buffer plan9buf; void checkerrs(void); +Buffer cmdbuf; +int cmdbufpos; int plan9(File *f, int type, String *s, int nest) @@ -28,7 +30,7 @@ plan9(File *f, int type, String *s, int nest) } if(type!='!' && pipe(pipe1)==-1) error(Epipe); - if(type=='|') + if(type=='|' || type=='_') snarf(f, addr.r.p1, addr.r.p2, &plan9buf, 1); if((pid=fork()) == 0){ if(downloaded){ /* also put nasty fd's into errfile */ @@ -48,14 +50,14 @@ plan9(File *f, int type, String *s, int nest) } } if(type != '!') { - if(type=='<' || type=='|') - dup(pipe1[1], 1); - else if(type == '>') + if(type == '>') dup(pipe1[0], 0); + else + dup(pipe1[1], 1); close(pipe1[0]); close(pipe1[1]); } - if(type == '|'){ + if(type == '|' || type == '_'){ if(pipe(pipe2) == -1) exits("pipe"); if((pid = fork())==0){ @@ -87,7 +89,7 @@ plan9(File *f, int type, String *s, int nest) close(pipe2[0]); close(pipe2[1]); } - if(type=='<'){ + if(type=='<' || type=='^'){ close(0); /* so it won't read from terminal */ open("/dev/null", 0); } @@ -115,9 +117,14 @@ plan9(File *f, int type, String *s, int nest) writeio(f); bpipeok = 0; closeio((Posn)-1); + }else if(type == '^' || type == '_'){ + int nulls; + close(pipe1[1]); + bufload(&cmdbuf, cmdbufpos, pipe1[0], &nulls); + close(pipe1[0]); } retmsg = waitfor(pid); - if(type=='|' || type=='<') + if(type=='|' || type=='<' || type=='_' || type=='^') if(retmsg[0]!=0) warn_s(Wbadstatus, retmsg); if(downloaded)