commit 0b2ea4c411ba2682d974a4474a835e11e4527ec7
parent 12ca2088bd26a972bab055c4917f1d30eb9fa5fe
Author: tdu <65677570+tdukv@users.noreply.github.com>
Date: Thu, 14 Oct 2021 19:53:59 +0000
Press 'b' to open a shell in current directory. Fixes #31
* Press 'b' to open a shell in current directory.
* update the man for the open shell feature
Diffstat:
3 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -103,6 +103,7 @@ static Key nkeys[] = {
{ {.ch = 'p'}, paste, {0} },
{ {.ch = 'P'}, selmv, {0} },
{ {.ch = 'c'}, start_change, {0} },
+ { {.ch = 'b'}, opnsh, {0} },
{ {.key = TB_KEY_SPACE}, switch_pane, {0} },
{ {.key = TB_KEY_CTRL_R}, refresh, {0} },
{ {.ch = '\\'}, bkmrk, {.v = root} },
diff --git a/sfm.1 b/sfm.1
@@ -63,6 +63,9 @@ paste
.B P
move
.TP
+.B b
+spawn a shell in the current directory
+.TP
.B c
start change
.TP
@@ -135,6 +138,9 @@ open unconfigured file extention. vi(1) if not set.
.TP
.B HOME
right pane default directory. / if not set.
+.TP
+.B SHELL
+shell spawned with the 'b' key. /bin/sh if not set.
.SH AUTHORS
See the LICENSE file for the authors.
.SH LICENSE
diff --git a/sfm.c b/sfm.c
@@ -182,6 +182,8 @@ static void refresh_pane(Pane *);
static void set_direntr(Pane *, struct dirent *, DIR *, char *);
static int listdir(Pane *);
static void t_resize(void);
+static void get_shell(void);
+static void opnsh(const Arg *arg);
static void set_panes(void);
static void draw_frame(void);
static void refresh(const Arg *arg);
@@ -194,6 +196,8 @@ static Pane *cpane;
static int pane_idx;
static char *editor[2];
static char fed[] = "vi";
+static char *shell[2];
+static char sh[] = "/bin/sh";
static int theight, twidth, hwidth, scrheight;
static int *sel_indexes;
static size_t sel_len = 0;
@@ -1062,6 +1066,21 @@ opnf(char *fn)
(char **)rules[c].v, rules[c].vlen, NULL, 0, fn, Wait);
}
+static void
+opnsh(const Arg *arg)
+{
+ int s;
+
+ tb_shutdown();
+ chdir(cpane->dirn);
+ s = spawn(shell, 1, NULL, 0, NULL, Wait);
+ if (tb_init() != 0)
+ die("tb_init");
+ t_resize();
+ if (s < 0)
+ print_error("process failed non-zero exit");
+}
+
static int
fsev_init(void)
{
@@ -1847,6 +1866,16 @@ get_editor(void)
}
static void
+get_shell(void)
+{
+ shell[0] = getenv("SHELL");
+ shell[1] = NULL;
+
+ if (shell[0] == NULL)
+ shell[0] = sh;
+}
+
+static void
set_panes(void)
{
char *home;
@@ -1975,6 +2004,7 @@ start(void)
draw_frame();
set_panes();
get_editor();
+ get_shell();
PERROR(start_signal() < 0);
PERROR(fsev_init() < 0);
PERROR(listdir(&panes[Left]) < 0);