From 7be85679c537110f799eae57aa135a317b253f32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=98yvind=20A=2E=20Holm?= <sunny@sunbase.org>
Date: Tue, 2 Jun 2015 04:06:09 +0200
Subject: [PATCH] Check for NCDU_SHELL environment variable when spawning shell

Check if the environment variable NCDU_SHELL is defined before the SHELL
variable is checked. This makes it possible to specify a program to
execute when 'b' is pressed. Setting SHELL to for example "mc" (Midnight
Commander) didn't work because mc already uses SHELL to execute
commands.
---
 doc/ncdu.pod | 12 +++++++++---
 src/shell.c  |  9 ++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/doc/ncdu.pod b/doc/ncdu.pod
index e0ba511..61a009b 100644
--- a/doc/ncdu.pod
+++ b/doc/ncdu.pod
@@ -214,9 +214,15 @@ Refresh/recalculate the current directory.
 
 Spawn shell in current directory.
 
-We first check the $SHELL environment variable of the user for the preferred
-shell interpreter. If it's not set, we fall back to the compile time
-configured default shell (usually /bin/bash).
+We first check the $NCDU_SHELL environment variable of the user for the
+preferred shell interpreter. If it's not set, $SHELL is checked. If that
+variable also isn't defined, we fall back to the compile time configured
+default shell (usually /bin/bash). This allows you to specify which program to
+launch when 'b' is pressed. For example, if you want ncdu to execute the
+Midnight Commander file manager in the current directory:
+
+  export NCDU_SHELL=mc
+  ncdu
 
 =item q
 
diff --git a/src/shell.c b/src/shell.c
index eb275cd..86d8095 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -52,9 +52,12 @@ void shell_draw() {
            "Press any key to continue.",
            full_path, res);
   } else {
-    char *shell = getenv("SHELL");
-    if (shell == NULL)
-      shell = DEFAULT_SHELL;
+    char *shell = getenv("NCDU_SHELL");
+    if (shell == NULL) {
+      shell = getenv("SHELL");
+      if (shell == NULL)
+        shell = DEFAULT_SHELL;
+    }
 
     res = system(shell);
 
-- 
GitLab