sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-newterm-0.8.2.diff (1947B)


      1 From a7eedc85e0609177cdb1ed3f6203fa37e6420012 Mon Sep 17 00:00:00 2001
      2 From: Matias Lang <yo@matiaslang.me>
      3 Date: Wed, 17 Jul 2019 01:10:44 -0300
      4 Subject: [PATCH] Add shortcut to spawn new terminal in the current dir
      5 
      6 Ctrl-Shift-Return now creates a new ST terminal, whose CWD is the same
      7 as the parent st's CWD
      8 ---
      9  config.def.h |  1 +
     10  st.c         | 21 +++++++++++++++++++++
     11  st.h         |  1 +
     12  3 files changed, 23 insertions(+)
     13 
     14 diff --git a/config.def.h b/config.def.h
     15 index 0e01717..31f26d8 100644
     16 --- a/config.def.h
     17 +++ b/config.def.h
     18 @@ -178,6 +178,7 @@ static Shortcut shortcuts[] = {
     19  	{ TERMMOD,              XK_Y,           selpaste,       {.i =  0} },
     20  	{ ShiftMask,            XK_Insert,      selpaste,       {.i =  0} },
     21  	{ TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
     22 +	{ TERMMOD,              XK_Return,      newterm,        {.i =  0} },
     23  };
     24  
     25  /*
     26 diff --git a/st.c b/st.c
     27 index b8e6077..044e29b 100644
     28 --- a/st.c
     29 +++ b/st.c
     30 @@ -153,6 +153,7 @@ typedef struct {
     31  } STREscape;
     32  
     33  static void execsh(char *, char **);
     34 +static char *getcwd_by_pid(pid_t pid);
     35  static void stty(char **);
     36  static void sigchld(int);
     37  static void ttywriteraw(const char *, size_t);
     38 @@ -1059,6 +1060,26 @@ tswapscreen(void)
     39  	tfulldirt();
     40  }
     41  
     42 +void
     43 +newterm(const Arg* a)
     44 +{
     45 +	switch (fork()) {
     46 +	case -1:
     47 +		die("fork failed: %s\n", strerror(errno));
     48 +		break;
     49 +	case 0:
     50 +		chdir(getcwd_by_pid(pid));
     51 +		execlp("st", "./st", NULL);
     52 +		break;
     53 +	}
     54 +}
     55 +
     56 +static char *getcwd_by_pid(pid_t pid) {
     57 +	char buf[32];
     58 +	snprintf(buf, sizeof buf, "/proc/%d/cwd", pid);
     59 +	return realpath(buf, NULL);
     60 +}
     61 +
     62  void
     63  tscrolldown(int orig, int n)
     64  {
     65 diff --git a/st.h b/st.h
     66 index 38c61c4..54d4a43 100644
     67 --- a/st.h
     68 +++ b/st.h
     69 @@ -80,6 +80,7 @@ void die(const char *, ...);
     70  void redraw(void);
     71  void draw(void);
     72  
     73 +void newterm(const Arg *);
     74  void printscreen(const Arg *);
     75  void printsel(const Arg *);
     76  void sendbreak(const Arg *);
     77 -- 
     78 2.19.2
     79