X-Git-Url: https://git.danieliu.xyz/?p=st.git;a=blobdiff_plain;f=x.c;h=5989947e47833ee89400313febb139401df56045;hp=b278a3454fd216c37ab0adf943f28cbd710c6218;hb=4649bab45b4c23489b6dea7cd6aa719060f39ce4;hpb=df9ce0019053c51e62d79979a5c0bd67a3beb64f diff --git a/x.c b/x.c index b278a34..5989947 100644 --- a/x.c +++ b/x.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ static void zoom(const Arg *); 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" @@ -196,11 +198,13 @@ static void selnotify(XEvent *); 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); @@ -231,6 +235,7 @@ static void (*handler[LASTEvent])(XEvent *) = { }; /* Globals */ +static int plumbsel; static DC dc; static XWindow xw; static XSelection xsel; @@ -345,6 +350,12 @@ ttysend(const Arg *arg) ttywrite(arg->s, strlen(arg->s), 1); } +void +plumber(const Arg *arg) +{ + plumb(xsel.primary); +} + int evcol(XEvent *e) { @@ -698,6 +709,37 @@ xsetsel(char *str) 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) { @@ -2130,6 +2172,7 @@ main(int argc, char *argv[]) } ARGEND; run: + plumbinit(); if (argc > 0) /* eat all remaining arguments */ opt_cmd = argv;