summaryrefslogtreecommitdiff
path: root/src/shell.c
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-05-12 16:30:31 +0200
committerYorhel <git@yorhel.nl>2021-05-12 16:30:43 +0200
commita6b4aead43cf7ecaa3f4d01503244a13e67b3f09 (patch)
tree6ae9702229004844c9f9497171ff629ecf144759 /src/shell.c
parente2786604643f3453501aebcfe5d9037dbb6e8a77 (diff)
Add $NCDU_LEVEL environment variable when spawning a shell
Similar to $SHLVL and $RANGER_LEVEL.
Diffstat (limited to 'src/shell.c')
-rw-r--r--src/shell.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shell.c b/src/shell.c
index fd589e6..b881700 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -34,6 +34,22 @@
#include <unistd.h>
#include <sys/wait.h>
+static void set_level(void) {
+ static int done = 0;
+ char nlvl[2];
+ if(done)
+ return;
+ const char *lvl = getenv("NCDU_LEVEL");
+ // too lazy to count beyond 9
+ if(lvl && *lvl >= '1' && *lvl < '9' && lvl[1] == 0) {
+ nlvl[0] = 1 + *lvl;
+ nlvl[1] = 0;
+ setenv("NCDU_LEVEL", nlvl, 1);
+ } else
+ setenv("NCDU_LEVEL", "1", 1);
+ done++;
+}
+
void shell_draw() {
const char *full_path;
int res;
@@ -59,6 +75,7 @@ void shell_draw() {
shell = DEFAULT_SHELL;
}
+ set_level();
res = system(shell);
/* resume ncurses mode */