applied newterm
[st.git] / st.c
diff --git a/st.c b/st.c
index 324c598..8c022b7 100644 (file)
--- 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)
 {