diff --git a/suckless/st/config.def.h b/suckless/st/config.def.h index 279890f..3e33614 100644 --- a/suckless/st/config.def.h +++ b/suckless/st/config.def.h @@ -206,6 +206,7 @@ static Shortcut shortcuts[] = { { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, + { TERMMOD, XK_Return, newterm, {.i = 0} }, }; /* diff --git a/suckless/st/st.c b/suckless/st/st.c index 0837c57..cd8d8f9 100644 --- a/suckless/st/st.c +++ b/suckless/st/st.c @@ -160,6 +160,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); @@ -1064,6 +1065,37 @@ tswapscreen(void) tfulldirt(); } +void +newterm(const Arg* a) +{ + int res; + switch (fork()) { + case -1: + die("fork failed: %s\n", strerror(errno)); + break; + case 0: + switch (fork()) { + case -1: + die("fork failed: %s\n", strerror(errno)); + break; + case 0: + res = chdir(getcwd_by_pid(pid)); + execlp("st", "./st", NULL); + break; + default: + exit(0); + } + default: + wait(NULL); + } +} + +static char *getcwd_by_pid(pid_t pid) { + char buf[32]; + snprintf(buf, sizeof buf, "/proc/%d/cwd", pid); + return realpath(buf, NULL); +} + void kscrolldown(const Arg* a) { diff --git a/suckless/st/st.h b/suckless/st/st.h index 01eea49..f638558 100644 --- a/suckless/st/st.h +++ b/suckless/st/st.h @@ -84,6 +84,7 @@ void draw(void); void kscrolldown(const Arg *); void kscrollup(const Arg *); +void newterm(const Arg *); void printscreen(const Arg *); void printsel(const Arg *); void sendbreak(const Arg *);