{ TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
        { MODKEY,               XK_c,           normalMode,     {.i =  0} },
        { ControlMask,          XK_Return,      newterm,        {.i =  0} },
+    { ControlMask,          XK_space,       plumber,        {.i =  0} },
 };
 
 /*
        " !\"#$%&'()*+,-./0123456789:;<=>?"
        "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
        "`abcdefghijklmnopqrstuvwxyz{|}~";
+
+/*
+ * plumb_cmd is run on mouse button 3 click, with first NULL set to
+ * current selection and with cwd set to the cwd of the active shell
+ */
+static char *plumb_cmd[] = {"plumb", "-m", NULL, NULL};
 
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
  #include <libutil.h>
 #endif
+#if defined(__OpenBSD__)
+ #include <sys/sysctl.h>
+#endif
 
 /* Arbitrary sizes */
 #define UTF_INVALID   0xFFFD
 static inline int rows() { return IS_SET(MODE_ALTSCREEN) ? term.row : buffSize;}
 static inline int rangeY(int i) { while (i < 0) i += rows(); return i % rows();}
 
+int
+subprocwd(char *path)
+{
+#if   defined(__linux)
+       if (snprintf(path, PATH_MAX, "/proc/%d/cwd", pid) < 0)
+               return -1;
+       return 0;
+#elif defined(__OpenBSD__)
+       size_t sz = PATH_MAX;
+       int name[3] = {CTL_KERN, KERN_PROC_CWD, pid};
+       if (sysctl(name, 3, path, &sz, 0, 0) == -1)
+               return -1;
+       return 0;
+#endif
+}
+
 ssize_t
 xwrite(int fd, const char *s, size_t len)
 {
                break;
        default:
 #ifdef __OpenBSD__
-               if (pledge("stdio rpath tty proc", NULL) == -1)
+               if (pledge("stdio rpath tty proc ps exec", NULL) == -1)
                        die("pledge\n");
 #endif
                close(s);
 
 void *xrealloc(void *, size_t);
 char *xstrdup(char *);
 
+int subprocwd(char *);
+
 /* config.h globals */
 extern char *utmp;
 extern char *scroll;
 
 #include <locale.h>
 #include <signal.h>
 #include <sys/select.h>
+#include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
 #include <libgen.h>
 static void zoomabs(const Arg *);
 static void zoomreset(const Arg *);
 static void ttysend(const Arg *);
+static void plumber(const Arg *);
 
 /* config.h for applying patches and the configuration. */
 #include "config.h"
 static void selclear_(XEvent *);
 static void selrequest(XEvent *);
 static void setsel(char *, Time);
+static void plumb(char *sel);
 static void mousesel(XEvent *, int);
 static void mousereport(XEvent *);
 static char *kmap(KeySym, uint);
 static int match(uint, uint);
 
+
 static void run(void);
 static void usage(void);
 
 };
 
 /* Globals */
+static int plumbsel;
 static DC dc;
 static XWindow xw;
 static XSelection xsel;
        ttywrite(arg->s, strlen(arg->s), 1);
 }
 
+void
+plumber(const Arg *arg)
+{
+    plumb(xsel.primary);
+}
+
 int
 evcol(XEvent *e)
 {
        setsel(str, CurrentTime);
 }
 
+void
+plumbinit()
+{
+       for(plumbsel = 0; plumb_cmd[plumbsel]; plumbsel++);
+}
+
+void
+plumb(char *sel) {
+       if (sel == NULL)
+               return;
+       char cwd[PATH_MAX];
+       pid_t child;
+       if (subprocwd(cwd) != 0)
+               return;
+
+       plumb_cmd[plumbsel] = sel;
+
+       switch(child = fork()) {
+               case -1:
+                       return;
+               case 0:
+                       if (chdir(cwd) != 0)
+                               exit(1);
+                       if (execvp(plumb_cmd[0], plumb_cmd) == -1)
+                               exit(1);
+                       exit(0);
+               default:
+                       waitpid(child, NULL, 0);
+       }
+}
+
 void
 brelease(XEvent *e)
 {
        } ARGEND;
 
 run:
+       plumbinit();
        if (argc > 0) /* eat all remaining arguments */
                opt_cmd = argv;