shithub: orca

Download patch

ref: 99dcd9586d4485fcdfcbe2d9511214b6bbbba7c5
parent: a79389ebf6faa1d0491d6ab188238cb28ab52511
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 21 12:22:25 EST 2020

plan9: add > and < pipe-style commands

--- a/orca.man
+++ b/orca.man
@@ -157,6 +157,13 @@
 to the command, and the other way around when it comes to command's
 output.
 .TP
+.B <cmd arg...
+Execute a shell command and paste its output into the grid. Dots are
+replaced with spaces.
+.TP
+.B >cmd arg...
+Pipe the selected text to a shell command. Dots are replaced with spaces.
+.TP
 .B play
 Resume.
 .TP
--- a/plan9.c
+++ b/plan9.c
@@ -197,7 +197,7 @@
 			cols = MIN(n, field.width-sel.min.x);
 		if (sel.min.y+rows < field.height) {
 			for (i = 0; i < n; i++)
-				if (s[i] == ' ')
+				if (!orca_is_valid_glyph(s[i]))
 					s[i] = '.';
 			memmove(&field.buffer[sel.min.x + field.width*(sel.min.y+rows)], s, MIN(n, field.width-sel.min.x));
 			rows++;
@@ -234,7 +234,7 @@
 	int x, y, p[4];
 	Glyph g;
 
-	shellcmd = s;
+	shellcmd = s+1;
 	pipe(p);
 	pipe(p+2);
 	procrfork(runshell, p, 4096, RFFDG);
@@ -242,7 +242,7 @@
 	close(p[3]);
 	out = Bfdopen(p[1], OWRITE);
 	in = Bfdopen(p[2], OREAD);
-	for (y = sel.min.y; y <= sel.max.y; y++) {
+	for (y = sel.min.y; *s != '<' && y <= sel.max.y; y++) {
 		for (x = sel.min.x; x <= sel.max.x; x++) {
 			if ((g = fieldget(x, y)) == '.')
 				g = ' ';
@@ -251,7 +251,8 @@
 		Bputc(out, '\n');
 	}
 	Bterm(out);
-	selpasteb(in);
+	if (*s != '>')
+		selpasteb(in);
 	Bterm(in);
 }
 
@@ -267,8 +268,8 @@
 		s++;
 	}
 
-	if (s[0] == '|') {
-		shellpipe(s+1);
+	if (s[0] == '|' || s[0] == '>' || s[0] == '<') {
+		shellpipe(s);
 		return;
 	}