Newterm patch - st - 💻 personal variant of st
(HTM) git clone https://git.drkhsh.at/st.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 36b11471606d377e8d484e427c602b9fb7ea78c4
(DIR) parent ccf474fcc66340a227b32dac2ec64f7f5fd3707f
(HTM) Author: drkhsh <me@drkhsh.at>
Date: Tue, 1 Jul 2025 20:14:18 +0200
Newterm patch
This patch allows you to spawn a new st terminal using
Ctrl-Shift-Return. It will have the same CWD (current working directory)
as the original st instance.
https://st.suckless.org/patches/newterm/
Diffstat:
M config.def.h | 1 +
A patch/newterm.c | 31 +++++++++++++++++++++++++++++++
A patch/newterm.h | 1 +
M st.c | 2 ++
M x.c | 1 +
5 files changed, 36 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/config.def.h b/config.def.h
@@ -210,6 +210,7 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
+ { TERMMOD, XK_Return, newterm, {.i = 0} },
};
/*
(DIR) diff --git a/patch/newterm.c b/patch/newterm.c
@@ -0,0 +1,31 @@
+extern char* argv0;
+
+static char*
+getcwd_by_pid(pid_t pid) {
+ static char cwd[32];
+ snprintf(cwd, sizeof cwd, "/proc/%d/cwd", pid);
+ return cwd;
+}
+
+void
+newterm(const Arg* a)
+{
+ switch (fork()) {
+ case -1:
+ die("fork failed: %s\n", strerror(errno));
+ break;
+ case 0:
+ switch (fork()) {
+ case -1:
+ die("fork failed: %s\n", strerror(errno));
+ break;
+ case 0:
+ chdir(getcwd_by_pid(pid));
+
+ execl("/proc/self/exe", argv0, NULL);
+ exit(1);
+ default:
+ exit(0);
+ }
+ }
+}
(DIR) diff --git a/patch/newterm.h b/patch/newterm.h
@@ -0,0 +1 @@
+void newterm(const Arg *);
(DIR) diff --git a/st.c b/st.c
@@ -215,6 +215,7 @@ 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};
+#include "patch/newterm.h"
#include "patch/reflow.h"
#include "patch/rightclicktoplumb.h"
@@ -2537,6 +2538,7 @@ drawregion(int x1, int y1, int x2, int y2)
}
}
+#include "patch/newterm.c"
#include "patch/reflow.c"
#include "patch/rightclicktoplumb_st.c"
(DIR) diff --git a/x.c b/x.c
@@ -39,6 +39,7 @@ static void zoomreset(const Arg *);
static void ttysend(const Arg *);
#include "patch/alpha.h"
+#include "patch/newterm.h"
#include "patch/reflow.h"
#include "patch/rightclicktoplumb.h"