[st] patch: newterm (orphan variant)

This commit is contained in:
dogeystamp 2024-01-02 11:38:04 -05:00
parent 521eab46e9
commit 9bed337341
3 changed files with 34 additions and 0 deletions

View File

@ -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} },
};
/*

View File

@ -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)
{

View File

@ -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 *);