commit fda0588d8043bcdb88b887755d9148d0cca4cffb
parent 2ccb1b7086bb6c7bd768954079208c49a2e81aef
Author: Tim Keller <tjkeller.xyz>
Date: Sun, 12 Jan 2025 14:15:16 -0600
add st patch "open selected text"
Diffstat:
2 files changed, 112 insertions(+), 0 deletions(-)
diff --git a/st.suckless.org/patches/open_selected_text/index.md b/st.suckless.org/patches/open_selected_text/index.md
@@ -0,0 +1,38 @@
+XDG-Open Selected
+=================
+This patch adds a function that can be bound to a key or button which attempts
+to open the selected text using `xdg-open`.
+
+Description
+-----------
+This functionality is most useful for opening URL's in a web-browser, but also
+allows you to open any type of file in the default application for its mimetype
+by having its path selected.
+
+By default, `CTRL + Mouse2` will open the selected text.
+
+OSC 7
+-----
+This patch also adds support for the `OSC 7` escape sequence, which allows for
+automatically changing the current working directory of st from a shell.
+
+This is useful because `xdg-open` is spawned as a child process of st, and so
+by default you won't be able to open a file using its relative path (unless
+that relative path happens to correspond with the CWD of st).
+
+To allow opening files using the relative path of the shell instead, you just
+need to add the following to your shell's rc:
+
+* zshrc: `function precmd () { builtin print -Pn "\e]7;file://${PWD}\a" }`
+* bashrc: `export PROMPT_COMMAND='echo -ne "\e]7;file://${PWD}\a"'`
+
+Setting this up will ensure that st's CWD is always synced with the CWD of your
+shell.
+
+Download
+--------
+* [st-open-selected-0.9.2.diff](st-open-selected-0.9.2.diff)
+
+Authors
+-------
+* Tim Keller - <tjk@tjkeller.xyz>
diff --git a/st.suckless.org/patches/open_selected_text/st-open-selected-0.9.2.diff b/st.suckless.org/patches/open_selected_text/st-open-selected-0.9.2.diff
@@ -0,0 +1,74 @@
+diff --git a/config.def.h b/config.def.h
+index 2cd740a..d362d6b 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -176,6 +176,7 @@ static uint forcemousemod = ShiftMask;
+ */
+ static MouseShortcut mshortcuts[] = {
+ /* mask button function argument release */
++ { ControlMask, Button2, selopen, {.i = 0}, 1 },
+ { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
+ { ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
+ { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
+diff --git a/st.c b/st.c
+index 2e3800e..f55facb 100644
+--- a/st.c
++++ b/st.c
+@@ -1903,6 +1903,16 @@ strhandle(void)
+ if (narg > 1)
+ xsettitle(strescseq.args[1]);
+ return;
++ case 7:
++ if (strstr(strescseq.args[1], "file://") != strescseq.args[1]) {
++ fprintf(stderr, "erresc: dir %s must have prefix 'file://'\n",
++ strescseq.args[1]);
++ return;
++ }
++ if (chdir(strescseq.args[1] + 7) != 0) /* +7 to remove prefix */
++ fprintf(stderr, "erresc: invalid directory %s\n",
++ strescseq.args[1]);
++ return;
+ case 52:
+ if (narg > 2 && allowwindowops) {
+ dec = base64dec(strescseq.args[2]);
+diff --git a/x.c b/x.c
+index d73152b..e44d61c 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 selopen(const Arg *);
+ static void zoom(const Arg *);
+ static void zoomabs(const Arg *);
+ static void zoomreset(const Arg *);
+@@ -286,6 +288,20 @@ selpaste(const Arg *dummy)
+ xw.win, CurrentTime);
+ }
+
++void
++selopen(const Arg *dummy)
++{
++ pid_t chpid;
++
++ if ((chpid = fork()) == 0) {
++ if (fork() == 0)
++ execlp("xdg-open", "xdg-open", getsel(), NULL);
++ exit(1);
++ }
++ if (chpid > 0)
++ waitpid(chpid, NULL, 0);
++}
++
+ void
+ numlock(const Arg *dummy)
+ {