aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjack <[email protected]>2024-04-26 10:36:06 -0600
committerjack <[email protected]>2024-04-26 10:36:06 -0600
commit9fa199b040142e755e0b3cc5c4e1bd78eee32c41 (patch)
tree2611df447b77bad3d606446a34cac29965891612
parent17cc1cac9088ca8ba8b97ba92cf758a1b0077008 (diff)
downloadst-9fa199b040142e755e0b3cc5c4e1bd78eee32c41.tar.gz
st-9fa199b040142e755e0b3cc5c4e1bd78eee32c41.zip
patch: new term from cwd
-rw-r--r--config.h3
-rw-r--r--st.c30
-rw-r--r--x.c2
3 files changed, 29 insertions, 6 deletions
diff --git a/config.h b/config.h
index 5e56fe1..ca86394 100644
--- a/config.h
+++ b/config.h
@@ -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;
diff --git a/st.c b/st.c
index 70d1c6b..73992ee 100644
--- a/st.c
+++ b/st.c
@@ -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;
diff --git a/x.c b/x.c
index abaccad..7705a3d 100644
--- a/x.c
+++ b/x.c
@@ -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"