aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-04-24 20:31:52 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-04-24 20:31:52 +0530
commit58e4b443a53facb9bb69370c35b1f3b3a0215eb8 (patch)
treee0b0f0e07051b7184386834bc833213e091d9126
parent32dde3390acf4f3cfcd9367a8875699e675db97b (diff)
downloadnnn-58e4b443a53facb9bb69370c35b1f3b3a0215eb8.tar.gz
Check binary config values are 1
-rw-r--r--README.md2
-rw-r--r--src/nnn.c35
2 files changed, 20 insertions, 17 deletions
diff --git a/README.md b/README.md
index 0046782..4327a39 100644
--- a/README.md
+++ b/README.md
@@ -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_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_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_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 |
diff --git a/src/nnn.c b/src/nnn.c
index c0f351f..eb361a1 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1049,6 +1049,17 @@ static char *xgetenv(const char *name, char *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 */
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) {
start = getenv(env_cfg[i]);
- if (start) {
- if (i < NNN_USE_EDITOR)
+ if (start)
dprintf(fd, "%s: %s\n", env_cfg[i], start);
- else
- dprintf(fd, "%s: 1\n", env_cfg[i]);
- }
}
if (g_cppath)
@@ -4108,10 +4115,6 @@ static bool setup_config(void)
xstrlcpy(cfgdir + r - 1, "/.config/nnn", len - r);
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 */
if (!create_dir(cfgdir)) {
xerror();
@@ -4284,7 +4287,7 @@ int main(int argc, char *argv[])
/* Get custom opener, if set */
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;
DPRINTF_S(opener);
@@ -4335,7 +4338,7 @@ int main(int argc, char *argv[])
}
/* Edit text in EDITOR, if opted */
- if (getenv(env_cfg[NNN_USE_EDITOR]))
+ if (xgetenv_set(env_cfg[NNN_USE_EDITOR]))
cfg.useeditor = 1;
/* Get VISUAL/EDITOR */
@@ -4377,7 +4380,7 @@ int main(int argc, char *argv[])
idletimeout = xatoi(getenv(env_cfg[NNN_IDLE_TIMEOUT]));
DPRINTF_U(idletimeout);
- if (getenv(env_cfg[NNN_TRASH]))
+ if (xgetenv_set(env_cfg[NNN_TRASH]))
cfg.trash = 1;
/* Prefix for temporary files */
@@ -4388,19 +4391,19 @@ int main(int argc, char *argv[])
copier = getenv(env_cfg[NNN_COPIER]);
/* Disable auto-select if opted */
- if (getenv(env_cfg[NNN_NO_AUTOSELECT]))
+ if (xgetenv_set(env_cfg[NNN_NO_AUTOSELECT]))
cfg.autoselect = 0;
/* 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;
/* Restrict opening of 0-byte files */
- if (getenv(env_cfg[NNN_RESTRICT_0B]))
+ if (xgetenv_set(env_cfg[NNN_RESTRICT_0B]))
cfg.restrict0b = 1;
#ifdef __linux__
- if (!getenv(env_cfg[NNN_OPS_PROG])) {
+ if (!xgetenv_set(env_cfg[NNN_OPS_PROG])) {
cp[5] = cp[4];
cp[2] = cp[4] = ' ';