From c492d94019c86ce9c33cc80c413ddf1248ed5ac7 Mon Sep 17 00:00:00 2001 From: _N0x Date: Sun, 22 Sep 2024 16:34:17 +0200 Subject: [PATCH] Added plumb patch --- st-0.9.2/config.def.h | 6 ++++++ st-0.9.2/st.c | 21 ++++++++++++++++++++- st-0.9.2/st.h | 2 ++ st-0.9.2/x.c | 26 ++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/st-0.9.2/config.def.h b/st-0.9.2/config.def.h index 977f4f1..46cf29c 100644 --- a/st-0.9.2/config.def.h +++ b/st-0.9.2/config.def.h @@ -479,3 +479,9 @@ static char ascii_printable[] = " !\"#$%&'()*+,-./0123456789:;<=>?" "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" "`abcdefghijklmnopqrstuvwxyz{|}~"; + +/* + * plumb_cmd is run on mouse button 3 click, with argument set to + * current selection and with cwd set to the cwd of the active shell + */ +static char *plumb_cmd = "plumb"; diff --git a/st-0.9.2/st.c b/st-0.9.2/st.c index 660d747..8ddcd0f 100644 --- a/st-0.9.2/st.c +++ b/st-0.9.2/st.c @@ -27,6 +27,9 @@ #elif defined(__FreeBSD__) || defined(__DragonFly__) #include #endif +#if defined(__OpenBSD__) + #include +#endif /* Arbitrary sizes */ #define UTF_INVALID 0xFFFD @@ -239,6 +242,22 @@ static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; static const Rune utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; static const Rune utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; +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) { @@ -810,7 +829,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) 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); diff --git a/st-0.9.2/st.h b/st-0.9.2/st.h index 01eea49..dd2e9c3 100644 --- a/st-0.9.2/st.h +++ b/st-0.9.2/st.h @@ -114,6 +114,8 @@ void *xmalloc(size_t); void *xrealloc(void *, size_t); char *xstrdup(const char *); +int subprocwd(char *); + /* config.h globals */ extern char *utmp; extern char *scroll; diff --git a/st-0.9.2/x.c b/st-0.9.2/x.c index 3f4f82a..ef3eaed 100644 --- a/st-0.9.2/x.c +++ b/st-0.9.2/x.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -700,6 +701,29 @@ xsetsel(char *str) setsel(str, CurrentTime); } +void +plumb(char *sel) { + if (sel == NULL) + return; + char cwd[PATH_MAX]; + pid_t child; + if (subprocwd(cwd) != 0) + return; + + switch(child = fork()) { + case -1: + return; + case 0: + if (chdir(cwd) != 0) + exit(1); + if (execvp(plumb_cmd, (char *const []){plumb_cmd, sel, 0}) == -1) + exit(1); + exit(0); + default: + waitpid(child, NULL, 0); + } +} + void brelease(XEvent *e) { @@ -717,6 +741,8 @@ brelease(XEvent *e) return; if (btn == Button1) mousesel(e, 1); + else if (e->xbutton.button == Button3) + plumb(xsel.primary); } void