sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit d43f8b2ca573273b99004a67f557d13fb5eeb046
parent 13dc0574919f4b7fbc598e719c6b4c94d3c2deee
Author: sewn <sewn@disroot.org>
Date:   Wed,  7 Jun 2023 16:16:28 +0300

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

Diffstat:
Mst.suckless.org/patches/right_click_to_plumb/index.md | 21+++++++++++++++++++++
Ast.suckless.org/patches/right_click_to_plumb/simpler_plumb-0.9.diff | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/st.suckless.org/patches/right_click_to_plumb/index.md b/st.suckless.org/patches/right_click_to_plumb/index.md @@ -105,3 +105,24 @@ Download Author ------ * yasumori <ysmr@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@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 @@ -0,0 +1,141 @@ +From d77f364af4d685a614545120d4fa28e9e3770c5e Mon Sep 17 00:00:00 2001 +From: sewn <sewn@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 +@@ -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. +@@ -181,6 +187,7 @@ static MouseShortcut mshortcuts[] = { + { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} }, + { ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} }, + { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} }, ++ { 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 +@@ -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}; +@@ -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 +@@ -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 *); +@@ -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 +@@ -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> +@@ -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 *); +@@ -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\n", strerror(errno)); ++ break; ++ case 0: ++ switch(fork()) { ++ case -1: ++ die("plumb failed: %s\n", 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 +