mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Check binary config values are 1
This commit is contained in:
parent
32dde3390a
commit
58e4b443a5
|
@ -375,7 +375,7 @@ The following indicators are used in the detail view:
|
||||||
| `NNN_COPIER='/absolute/path/to/copier'` | system clipboard copier script [default: none] |
|
| `NNN_COPIER='/absolute/path/to/copier'` | system clipboard copier script [default: none] |
|
||||||
| `NNN_NOTE=/home/user/Dropbox/notes` | path to note file [default: none] |
|
| `NNN_NOTE=/home/user/Dropbox/notes` | path to note file [default: none] |
|
||||||
| `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit |
|
| `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit |
|
||||||
| `NNN_USE_EDITOR=1` | Open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) |
|
| `NNN_USE_EDITOR=1` | open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) |
|
||||||
| `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type_ mode |
|
| `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type_ mode |
|
||||||
| `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd> ↵</kbd>, not <kbd>→</kbd> or <kbd>l</kbd> |
|
| `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd> ↵</kbd>, not <kbd>→</kbd> or <kbd>l</kbd> |
|
||||||
| `NNN_RESTRICT_0B=1` | do not open 0-byte files |
|
| `NNN_RESTRICT_0B=1` | do not open 0-byte files |
|
||||||
|
|
35
src/nnn.c
35
src/nnn.c
|
@ -1049,6 +1049,17 @@ static char *xgetenv(const char *name, char *fallback)
|
||||||
return value && value[0] ? value : fallback;
|
return value && value[0] ? value : fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Checks if an env variable is set to 1 */
|
||||||
|
static bool xgetenv_set(const char *name)
|
||||||
|
{
|
||||||
|
char *value = getenv(name);
|
||||||
|
|
||||||
|
if (value && value[0] == 1 && !value[1])
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if a dir exists, IS a dir and is readable */
|
/* Check if a dir exists, IS a dir and is readable */
|
||||||
static bool xdiraccess(const char *path)
|
static bool xdiraccess(const char *path)
|
||||||
{
|
{
|
||||||
|
@ -2559,12 +2570,8 @@ static bool show_help(const char *path)
|
||||||
|
|
||||||
for (i = NNN_OPENER; i <= NNN_TRASH; ++i) {
|
for (i = NNN_OPENER; i <= NNN_TRASH; ++i) {
|
||||||
start = getenv(env_cfg[i]);
|
start = getenv(env_cfg[i]);
|
||||||
if (start) {
|
if (start)
|
||||||
if (i < NNN_USE_EDITOR)
|
|
||||||
dprintf(fd, "%s: %s\n", env_cfg[i], start);
|
dprintf(fd, "%s: %s\n", env_cfg[i], start);
|
||||||
else
|
|
||||||
dprintf(fd, "%s: 1\n", env_cfg[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_cppath)
|
if (g_cppath)
|
||||||
|
@ -4108,10 +4115,6 @@ static bool setup_config(void)
|
||||||
xstrlcpy(cfgdir + r - 1, "/.config/nnn", len - r);
|
xstrlcpy(cfgdir + r - 1, "/.config/nnn", len - r);
|
||||||
DPRINTF_S(cfgdir);
|
DPRINTF_S(cfgdir);
|
||||||
|
|
||||||
/* TODO: remove in next release */
|
|
||||||
if (access(cfgdir, F_OK) == -1)
|
|
||||||
fprintf(stdout, "WARNING: selection file is ~/.config/nnn/.selection (see CHANGELOG)\n");
|
|
||||||
|
|
||||||
/* Create ~/.config/nnn */
|
/* Create ~/.config/nnn */
|
||||||
if (!create_dir(cfgdir)) {
|
if (!create_dir(cfgdir)) {
|
||||||
xerror();
|
xerror();
|
||||||
|
@ -4284,7 +4287,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Get custom opener, if set */
|
/* Get custom opener, if set */
|
||||||
opener = xgetenv(env_cfg[NNN_OPENER], utils[OPENER]);
|
opener = xgetenv(env_cfg[NNN_OPENER], utils[OPENER]);
|
||||||
if (getenv(env_cfg[NNN_OPENER_DETACH]))
|
if (xgetenv_set(env_cfg[NNN_OPENER_DETACH]))
|
||||||
opener_flag |= F_NOWAIT;
|
opener_flag |= F_NOWAIT;
|
||||||
DPRINTF_S(opener);
|
DPRINTF_S(opener);
|
||||||
|
|
||||||
|
@ -4335,7 +4338,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Edit text in EDITOR, if opted */
|
/* Edit text in EDITOR, if opted */
|
||||||
if (getenv(env_cfg[NNN_USE_EDITOR]))
|
if (xgetenv_set(env_cfg[NNN_USE_EDITOR]))
|
||||||
cfg.useeditor = 1;
|
cfg.useeditor = 1;
|
||||||
|
|
||||||
/* Get VISUAL/EDITOR */
|
/* Get VISUAL/EDITOR */
|
||||||
|
@ -4377,7 +4380,7 @@ int main(int argc, char *argv[])
|
||||||
idletimeout = xatoi(getenv(env_cfg[NNN_IDLE_TIMEOUT]));
|
idletimeout = xatoi(getenv(env_cfg[NNN_IDLE_TIMEOUT]));
|
||||||
DPRINTF_U(idletimeout);
|
DPRINTF_U(idletimeout);
|
||||||
|
|
||||||
if (getenv(env_cfg[NNN_TRASH]))
|
if (xgetenv_set(env_cfg[NNN_TRASH]))
|
||||||
cfg.trash = 1;
|
cfg.trash = 1;
|
||||||
|
|
||||||
/* Prefix for temporary files */
|
/* Prefix for temporary files */
|
||||||
|
@ -4388,19 +4391,19 @@ int main(int argc, char *argv[])
|
||||||
copier = getenv(env_cfg[NNN_COPIER]);
|
copier = getenv(env_cfg[NNN_COPIER]);
|
||||||
|
|
||||||
/* Disable auto-select if opted */
|
/* Disable auto-select if opted */
|
||||||
if (getenv(env_cfg[NNN_NO_AUTOSELECT]))
|
if (xgetenv_set(env_cfg[NNN_NO_AUTOSELECT]))
|
||||||
cfg.autoselect = 0;
|
cfg.autoselect = 0;
|
||||||
|
|
||||||
/* Disable opening files on right arrow and `l` */
|
/* Disable opening files on right arrow and `l` */
|
||||||
if (getenv(env_cfg[NNN_RESTRICT_NAV_OPEN]))
|
if (xgetenv_set(env_cfg[NNN_RESTRICT_NAV_OPEN]))
|
||||||
cfg.nonavopen = 1;
|
cfg.nonavopen = 1;
|
||||||
|
|
||||||
/* Restrict opening of 0-byte files */
|
/* Restrict opening of 0-byte files */
|
||||||
if (getenv(env_cfg[NNN_RESTRICT_0B]))
|
if (xgetenv_set(env_cfg[NNN_RESTRICT_0B]))
|
||||||
cfg.restrict0b = 1;
|
cfg.restrict0b = 1;
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (!getenv(env_cfg[NNN_OPS_PROG])) {
|
if (!xgetenv_set(env_cfg[NNN_OPS_PROG])) {
|
||||||
cp[5] = cp[4];
|
cp[5] = cp[4];
|
||||||
cp[2] = cp[4] = ' ';
|
cp[2] = cp[4] = ' ';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue