From b8ecd1869e364f4f7fed2c819240d7de30b97721 Mon Sep 17 00:00:00 2001 From: tsxv478 Date: Sun, 17 Jul 2022 04:33:36 +0300 Subject: newterm orphan patch --- config.def.h | 1 + st.c | 32 ++++++++++++++++++++++++++++++++ st.h | 1 + 3 files changed, 34 insertions(+) diff --git a/config.def.h b/config.def.h index 29c35f1..5634b75 100644 --- a/config.def.h +++ b/config.def.h @@ -222,6 +222,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} }, { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, }; diff --git a/st.c b/st.c index f0d5f8a..a778e61 100644 --- a/st.c +++ b/st.c @@ -181,6 +181,7 @@ typedef struct { } STREscape; static void execsh(char *, char **); +static char *getcwd_by_pid(pid_t pid); static void stty(char **); static void sigchld(int); static void ttywriteraw(const char *, size_t); @@ -1089,6 +1090,37 @@ tcursor(int mode) } } +void +newterm(const Arg* a) +{ + int res; + 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: + res = chdir(getcwd_by_pid(pid)); + execlp("st", "./st", NULL); + break; + default: + exit(0); + } + default: + wait(NULL); + } +} + +static char *getcwd_by_pid(pid_t pid) { + char buf[32]; + snprintf(buf, sizeof buf, "/proc/%d/cwd", pid); + return realpath(buf, NULL); +} + void tresetcursor(void) { diff --git a/st.h b/st.h index 665cac0..66843f0 100644 --- a/st.h +++ b/st.h @@ -86,6 +86,7 @@ void draw(void); void kscrolldown(const Arg *); void kscrollup(const Arg *); +void newterm(const Arg *); void printscreen(const Arg *); void printsel(const Arg *); void sendbreak(const Arg *); -- cgit v1.2.3