I think it would be really neat to be able to send all the
text in a terminal to an external program, to act on it as
it likes.
I wrote a patch to do that, sending the contents of the
screen to the stdin of the chosen program.
One good use for this is writing a script to find any links,
and offer to open them in a browser using dmenu. A
particularly crude version of this could be:
#!/bin/sh
sed -e '/http/!d' -e 's/.*http/http/g' -e 's/ .*//g' | dmenu | xargs surf
There are a couple of things which need fixing / could do
with some discussion:
1) At present I commented out the SIGCHLD handler, as it was
blocking the process from returning. I confess to not being
overly familiar with the finer points of forking, so hope
someone better than me can suggest a fix.
2) This could be a feature that people would find useful to
trigger several different scripts. At present the key
binding is hardcoded (meta-|); should we add something to
be able to better define keybindings in config.h?
diff -r 1c8e6796c6fe config.def.h
--- a/config.def.h Sun Aug 14 17:15:19 2011 +0200
+++ b/config.def.h Thu Aug 25 15:40:02 2011 +0100
@@ -72,3 +72,5 @@
/* double-click timeout (in milliseconds) between clicks for selection */
#define DOUBLECLICK_TIMEOUT 300
#define TRIPLECLICK_TIMEOUT (2*DOUBLECLICK_TIMEOUT)
+
+static const char *pipecmd[] = { "pipetest.sh", NULL };
diff -r 1c8e6796c6fe st.c
--- a/st.c Sun Aug 14 17:15:19 2011 +0200
+++ b/st.c Thu Aug 25 15:40:02 2011 +0100
@@ -232,6 +232,8 @@
static void selcopy(void);
static void selpaste();
+static void extpipe();
+
static int utf8decode(char *, long *);
static int utf8encode(long *, char *);
static int utf8size(char *);
@@ -607,6 +609,37 @@
}
void
+extpipe(const char **cmd) {
+ int fd[2], pid;
+
+ if(pipe(fd)) return;
+ pid = fork();
+
+ if(pid == -1) return;
+ if(pid == 0) { /* child */
+ close(fd[1]);
+ if(fd[0] != STDIN_FILENO) {
+ dup2(fd[0], STDIN_FILENO);
+ close(fd[0]);
+ }
+ execvp(cmd[0], (char **)cmd);
+ exit(0);
+ } else { /* parent */
+ int x, y;
+ close(fd[0]);
+
+ for(y = 0; y < term.row; y++) {
+ for(x = 0; x < term.col; x++) {
+ if(term.line[y][x].state & GLYPH_SET)
+ write(fd[1], term.line[y][x].c, utf8size(term.line[y][x].c));
+ }
+ write(fd[1], "\n", 1);
+ }
+ close(fd[1]);
+ }
+}
+
+void
bmotion(XEvent *e) {
if(IS_SET(MODE_MOUSE)) {
mousereport(e);
@@ -684,7 +717,7 @@
default:
close(s);
cmdfd = m;
- signal(SIGCHLD, sigchld);
+ //signal(SIGCHLD, sigchld);
}
}
@@ -1877,6 +1910,10 @@
if(shift)
selpaste();
break;
+ case XK_bar:
+ if(meta)
+ extpipe(pipecmd);
+ break;
case XK_Return:
if(IS_SET(MODE_CRLF))
ttywrite("\r\n", 2);