[wiki] [sites] [st][patch] Add newterm || Matías Lang

From: <git_AT_suckless.org>
Date: Wed, 17 Jul 2019 06:30:29 +0200

commit 3d385cbeac3f4daf95a8dd373e5f57b5b77cf390
Author: Matías Lang <yo_AT_matiaslang.me>
Date: Wed Jul 17 01:27:55 2019 -0300

    [st][patch] Add newterm

diff --git a/st.suckless.org/patches/newterm/index.md b/st.suckless.org/patches/newterm/index.md
new file mode 100644
index 00000000..80c011ac
--- /dev/null
+++ b/st.suckless.org/patches/newterm/index.md
_AT_@ -0,0 +1,17 @@
+New terminal in current directory
+=================================
+
+This patch allows you to spawn a new st terminal using Ctrl-Shift-Return. It
+will have the same CWD (current working directory) as the original st instance.
+
+The `getcwd_by_pid` function is inspired on [the function with the same name of
+dvtm](https://github.com/martanne/dvtm/blob/master/dvtm.c#L1027).
+
+Download
+--------
+
+* [st-newterm-0.8.2.diff](st-newterm-0.8.2.diff)
+
+Authors
+-------
+* Matías Lang
diff --git a/st.suckless.org/patches/newterm/st-newterm-0.8.2.diff b/st.suckless.org/patches/newterm/st-newterm-0.8.2.diff
new file mode 100644
index 00000000..629508af
--- /dev/null
+++ b/st.suckless.org/patches/newterm/st-newterm-0.8.2.diff
_AT_@ -0,0 +1,79 @@
+From a7eedc85e0609177cdb1ed3f6203fa37e6420012 Mon Sep 17 00:00:00 2001
+From: Matias Lang <yo_AT_matiaslang.me>
+Date: Wed, 17 Jul 2019 01:10:44 -0300
+Subject: [PATCH] Add shortcut to spawn new terminal in the current dir
+
+Ctrl-Shift-Return now creates a new ST terminal, whose CWD is the same
+as the parent st's CWD
+---
+ config.def.h | 1 +
+ st.c | 21 +++++++++++++++++++++
+ st.h | 1 +
+ 3 files changed, 23 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 0e01717..31f26d8 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -178,6 +178,7 @@ static Shortcut shortcuts[] = {
+ { TERMMOD, XK_Y, selpaste, {.i = 0} },
+ { ShiftMask, XK_Insert, selpaste, {.i = 0} },
+ { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
++ { TERMMOD, XK_Return, newterm, {.i = 0} },
+ };
+
+ /*
+diff --git a/st.c b/st.c
+index b8e6077..044e29b 100644
+--- a/st.c
++++ b/st.c
+_AT_@ -153,6 +153,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);
+_AT_@ -1059,6 +1060,26 @@ tswapscreen(void)
+ tfulldirt();
+ }
+
++void
++newterm(const Arg* a)
++{
++ switch (fork()) {
++ case -1:
++ die("fork failed: %s
", 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)
+ {
+diff --git a/st.h b/st.h
+index 38c61c4..54d4a43 100644
+--- a/st.h
++++ b/st.h
+_AT_@ -80,6 +80,7 @@ void die(const char *, ...);
+ void redraw(void);
+ void draw(void);
+
++void newterm(const Arg *);
+ void printscreen(const Arg *);
+ void printsel(const Arg *);
+ void sendbreak(const Arg *);
+--
+2.19.2
+
Received on Wed Jul 17 2019 - 06:30:29 CEST

This archive was generated by hypermail 2.3.0 : Wed Jul 17 2019 - 06:36:30 CEST