mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-14 17:58:40 -09:00
Add $NCDU_LEVEL environment variable when spawning a shell
Similar to $SHLVL and $RANGER_LEVEL.
This commit is contained in:
parent
e278660464
commit
a6b4aead43
2 changed files with 23 additions and 0 deletions
|
|
@ -287,6 +287,12 @@ run ncdu as follows:
|
||||||
export NCDU_SHELL=vifm
|
export NCDU_SHELL=vifm
|
||||||
ncdu
|
ncdu
|
||||||
|
|
||||||
|
Ncdu will set the C<NCDU_LEVEL> environment variable or increment it before
|
||||||
|
spawning the shell. This variable allows you to detect when your shell is
|
||||||
|
running from within ncdu, which can be useful to avoid nesting multiple
|
||||||
|
instances of ncdu. Ncdu itself does not (currently) warn when attempting to run
|
||||||
|
nested instances.
|
||||||
|
|
||||||
=item q
|
=item q
|
||||||
|
|
||||||
Quit
|
Quit
|
||||||
|
|
|
||||||
17
src/shell.c
17
src/shell.c
|
|
@ -34,6 +34,22 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.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() {
|
void shell_draw() {
|
||||||
const char *full_path;
|
const char *full_path;
|
||||||
int res;
|
int res;
|
||||||
|
|
@ -59,6 +75,7 @@ void shell_draw() {
|
||||||
shell = DEFAULT_SHELL;
|
shell = DEFAULT_SHELL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_level();
|
||||||
res = system(shell);
|
res = system(shell);
|
||||||
|
|
||||||
/* resume ncurses mode */
|
/* resume ncurses mode */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue