diff options
author | jack <[email protected]> | 2024-04-26 10:36:06 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-04-26 10:36:06 -0600 |
commit | 9fa199b040142e755e0b3cc5c4e1bd78eee32c41 (patch) | |
tree | 2611df447b77bad3d606446a34cac29965891612 | |
parent | 17cc1cac9088ca8ba8b97ba92cf758a1b0077008 (diff) | |
download | st-9fa199b040142e755e0b3cc5c4e1bd78eee32c41.tar.gz st-9fa199b040142e755e0b3cc5c4e1bd78eee32c41.zip |
patch: new term from cwd
-rw-r--r-- | config.h | 3 | ||||
-rw-r--r-- | st.c | 30 | ||||
-rw-r--r-- | x.c | 2 |
3 files changed, 29 insertions, 6 deletions
@@ -53,7 +53,8 @@ MouseKey mkeys[] = { static Shortcut shortcuts[] = { {ControlMask | ShiftMask, XK_V, clippaste, {.i = 0}}, - {ControlMask | ShiftMask, XK_C, clipcopy, {.i = 0}}}; + {ControlMask | ShiftMask, XK_C, clipcopy, {.i = 0}}, + {ControlMask, XK_t, newterm, {.i = 0}}}; static KeySym mappedkeys[] = {-1}; static uint ignoremod = Mod2Mask | XK_SWITCH_MOD; @@ -22,6 +22,8 @@ #include "st.h" #include "win.h" +extern char *argv0; + #if defined(__linux) #include <pty.h> #elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) @@ -49,7 +51,7 @@ #define TLINE(y) \ ((y) < term.scr \ ? term.hist[((y) + term.histi - term.scr + HISTSIZE + 1) % HISTSIZE] \ - : term.line[(y) - term.scr]) + : term.line[(y)-term.scr]) #define TLINE_HIST(y) \ ((y) <= HISTSIZE - term.row + 2 ? term.hist[(y)] \ @@ -171,6 +173,7 @@ typedef struct { static void execsh(char *, char **); static char *getcwd_by_pid(pid_t pid); +static int chdir_by_pid(pid_t pid); static void stty(char **); static void sigchld(int); static void ttywriteraw(const char *, size_t); @@ -775,6 +778,7 @@ int 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); @@ -1002,9 +1006,21 @@ void newterm(const Arg *a) { die("fork failed: %s\n", strerror(errno)); break; case 0: - chdir(getcwd_by_pid(pid)); - execlp("st", "./st", NULL); - break; + 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); } } @@ -1014,6 +1030,12 @@ static char *getcwd_by_pid(pid_t pid) { return realpath(buf, 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 kscrolldown(const Arg *a) { int n = a->i; @@ -16,7 +16,7 @@ #include <X11/Xft/Xft.h> #include <X11/XKBlib.h> -static char *argv0; +char *argv0; #include "arg.h" #include "st.h" #include "win.h" |