From: Daniel Liu Date: Mon, 1 Feb 2021 04:34:21 +0000 (-0500) Subject: applied newterm X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=61e4c929b5fb727c43b60aacf33b56d716d13587;p=st.git applied newterm --- diff --git a/config.def.h b/config.def.h index 399ef1f..a8da214 100644 --- a/config.def.h +++ b/config.def.h @@ -257,6 +257,7 @@ static Shortcut shortcuts[] = { { ShiftMask, XK_Insert, selpaste, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { MODKEY, XK_c, normalMode, {.i = 0} }, + { TERMMOD, XK_Return, newterm, {.i = 0} }, }; /* diff --git a/st.c b/st.c index 324c598..8c022b7 100644 --- a/st.c +++ b/st.c @@ -157,6 +157,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); @@ -1061,6 +1062,26 @@ tswapscreen(void) tfulldirt(); } +void +newterm(const Arg* a) +{ + switch (fork()) { + case -1: + die("fork failed: %s\n", strerror(errno)); + break; + case 0: + chdir(getcwd_by_pid(pid)); + execlp("st", "./st", NULL); + break; + } +} + +static char *getcwd_by_pid(pid_t pid) { + char buf[32]; + snprintf(buf, sizeof buf, "/proc/%d/cwd", pid); + return realpath(buf, NULL); +} + void tscrolldown(int orig, int n) { diff --git a/st.h b/st.h index b79ac2f..9404925 100644 --- a/st.h +++ b/st.h @@ -82,6 +82,7 @@ void die(const char *, ...); void redraw(void); void draw(void); +void newterm(const Arg *); void printscreen(const Arg *); void printsel(const Arg *); void sendbreak(const Arg *);