st

my st build
Log | Files | Refs | README | LICENSE

commit 870d2521456d5f81e84fc27cf4b06d700a9c6b62
parent f0b5e0d40c2637290bad4936b44ddb2c1f841527
Author: ssnf <ssnf@ssnf.xyz>
Date:   Fri, 25 Nov 2022 12:57:57 +0000

newterm patch

Diffstat:
Mconfig.h | 1+
Mst.c | 38++++++++++++++++++++++++++++++++++++++
Mst.h | 1+
3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/config.h b/config.h @@ -205,6 +205,7 @@ static Shortcut shortcuts[] = { { TERMMOD, XK_Y, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, + { MODKEY, XK_Return, newterm, {.i = 0} }, }; /* diff --git a/st.c b/st.c @@ -20,6 +20,8 @@ #include "st.h" #include "win.h" +extern char *argv0; + #if defined(__linux) #include <pty.h> #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) @@ -153,6 +155,7 @@ typedef struct { } STREscape; static void execsh(char *, char **); +static int chdir_by_pid(pid_t pid); static void stty(char **); static void sigchld(int); static void ttywriteraw(const char *, size_t); @@ -805,6 +808,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) if (pledge("stdio rpath tty proc", NULL) == -1) die("pledge\n"); #endif + fcntl(m, F_SETFD, FD_CLOEXEC); close(s); cmdfd = m; signal(SIGCHLD, sigchld); @@ -1054,6 +1058,40 @@ tswapscreen(void) } void +newterm(const Arg* a) +{ + switch (fork()) { + case -1: + die("fork failed: %s\n", strerror(errno)); + break; + case 0: + switch (fork()) { + case -1: + fprintf(stderr, "fork failed: %s\n", strerror(errno)); + _exit(1); + break; + case 0: + chdir_by_pid(pid); + execl("/proc/self/exe", argv0, NULL); + _exit(1); + break; + default: + _exit(0); + } + default: + wait(NULL); + } +} + +static 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) { int i; diff --git a/st.h b/st.h @@ -82,6 +82,7 @@ void redraw(void); void tfulldirt(void); void draw(void); +void newterm(const Arg *); void printscreen(const Arg *); void printsel(const Arg *); void sendbreak(const Arg *);