[wiki] [sites] [st][patch][right_click_to_plumb] add another simple variant || sewn

From: <git_AT_suckless.org>
Date: Wed, 07 Jun 2023 22:17:07 +0200

commit d43f8b2ca573273b99004a67f557d13fb5eeb046
Author: sewn <sewn_AT_disroot.org>
Date: Wed Jun 7 16:16:28 2023 +0300

    [st][patch][right_click_to_plumb] add another simple variant

diff --git a/st.suckless.org/patches/right_click_to_plumb/index.md b/st.suckless.org/patches/right_click_to_plumb/index.md
index 405e5ca4..8fb861fc 100644
--- a/st.suckless.org/patches/right_click_to_plumb/index.md
+++ b/st.suckless.org/patches/right_click_to_plumb/index.md
_AT_@ -105,3 +105,24 @@ Download
 Author
 ------
 * yasumori <ysmr_AT_protonmail.com>
+
+An even simpler plumb patch
+===========================
+The differences of this patch to the simple, flexible plumb patch:
+
+* The code for retrieving and setting the current working directory and executing is the
+ same as newterm, if patching with newterm it is suggested to keep the same function, hence
+ no global variables and initialization, and current selection of plumb.
+* Double-fork execution of the plumber program, while this may have no benefit with programs
+ that only launch in CLI, this may interfere with the swallow patch if launching GUI programs.
+* No arguments are passed to the plumber program, only the plumber program name is accepted.
+* The plumb function can be passed to the mouse shortcuts in `config.h`,
+ instead of being hard-coded.
+
+Download
+--------
+* [simpler\_plumb-0.9.diff](simpler_plumb-0.9.diff)
+
+Author
+------
+* sewn <sewn_AT_disroot.org>
diff --git a/st.suckless.org/patches/right_click_to_plumb/simpler_plumb-0.9.diff b/st.suckless.org/patches/right_click_to_plumb/simpler_plumb-0.9.diff
new file mode 100644
index 00000000..5206b42e
--- /dev/null
+++ b/st.suckless.org/patches/right_click_to_plumb/simpler_plumb-0.9.diff
_AT_@ -0,0 +1,141 @@
+From d77f364af4d685a614545120d4fa28e9e3770c5e Mon Sep 17 00:00:00 2001
+From: sewn <sewn_AT_disroot.org>
+Date: Wed, 7 Jun 2023 14:46:03 +0300
+Subject: [PATCH] Pass selected text to a plumber program
+
+---
+ config.def.h | 7 +++++++
+ st.c | 11 ++++++++++-
+ st.h | 4 ++++
+ x.c | 28 ++++++++++++++++++++++++++++
+ 4 files changed, 49 insertions(+), 1 deletion(-)
+
+diff --git a/config.def.h b/config.def.h
+index 91ab8ca..1f5b17a 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -170,6 +170,12 @@ static unsigned int defaultattr = 11;
+ */
+ static uint forcemousemod = ShiftMask;
+
++/*
++ * Default plumber program. The selected text will be passed as an argument.
++ * No other arguments can be passed.
++ */
++static char plumber[] = "plumber";
++
+ /*
+ * Internal mouse shortcuts.
+ * Beware that overloading Button1 will disable the selection.
+_AT_@ -181,6 +187,7 @@ static MouseShortcut mshortcuts[] = {
+ { XK_ANY_MOD, Button4, ttysend, {.s = ""} },
+ { ShiftMask, Button5, ttysend, {.s = "[6;2~"} },
+ { XK_ANY_MOD, Button5, ttysend, {.s = ""} },
++ { XK_NO_MOD, Button3, plumb, {.i = 0}, },
+ };
+
+ /* Internal keyboard shortcuts. */
+diff --git a/st.c b/st.c
+index 134e724..626efa3 100644
+--- a/st.c
++++ b/st.c
+_AT_@ -225,7 +225,8 @@ static CSIEscape csiescseq;
+ static STREscape strescseq;
+ static int iofd = 1;
+ static int cmdfd;
+-static pid_t pid;
++
++pid_t pid;
+
+ static const uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
+ static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
+_AT_@ -1054,6 +1055,14 @@ tswapscreen(void)
+ tfulldirt();
+ }
+
++int
++chdir_by_pid(pid_t pid)
++{
++ char buf[32];
++ snprintf(buf, sizeof buf, "/proc/%ld/cwd", (long)pid);
++ return chdir(buf);
++}
++
+ void
+ tscrolldown(int orig, int n)
+ {
+diff --git a/st.h b/st.h
+index fd3b0d8..cca6468 100644
+--- a/st.h
++++ b/st.h
+_AT_@ -81,6 +81,8 @@ void die(const char *, ...);
+ void redraw(void);
+ void draw(void);
+
++int chdir_by_pid(pid_t pid);
++
+ void printscreen(const Arg *);
+ void printsel(const Arg *);
+ void sendbreak(const Arg *);
+_AT_@ -124,3 +126,5 @@ extern unsigned int tabspaces;
+ extern unsigned int defaultfg;
+ extern unsigned int defaultbg;
+ extern unsigned int defaultcs;
++
++extern pid_t pid;
+diff --git a/x.c b/x.c
+index aa09997..1cca84e 100644
+--- a/x.c
++++ b/x.c
+_AT_@ -5,6 +5,7 @@
+ #include <locale.h>
+ #include <signal.h>
+ #include <sys/select.h>
++#include <sys/wait.h>
+ #include <time.h>
+ #include <unistd.h>
+ #include <libgen.h>
+_AT_@ -55,6 +56,7 @@ static void clipcopy(const Arg *);
+ static void clippaste(const Arg *);
+ static void numlock(const Arg *);
+ static void selpaste(const Arg *);
++static void plumb(const Arg *);
+ static void zoom(const Arg *);
+ static void zoomabs(const Arg *);
+ static void zoomreset(const Arg *);
+_AT_@ -292,6 +294,32 @@ numlock(const Arg *dummy)
+ win.mode ^= MODE_NUMLOCK;
+ }
+
++void
++plumb(const Arg *dummy)
++{
++ switch(fork()) {
++ case -1:
++ die("plumb failed: %s
", strerror(errno));
++ break;
++ case 0:
++ switch(fork()) {
++ case -1:
++ die("plumb failed: %s
", strerror(errno));
++ _exit(1);
++ break;
++ case 0:
++ chdir_by_pid(pid);
++ execlp(plumber, plumber, xsel.primary, NULL);
++ _exit(127);
++ break;
++ default:
++ _exit(0);
++ }
++ default:
++ wait(NULL);
++ }
++}
++
+ void
+ zoom(const Arg *arg)
+ {
+--
+2.40.1
+
Received on Wed Jun 07 2023 - 22:17:07 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 07 2023 - 22:24:55 CEST