README.md | 9 ++++++++-
nnn.1 | 5 +++++
src/nnn.c | 14 ++++++++++++--
diff --git a/README.md b/README.md
index 27f30734255e484e0ac2366d2fae0ce6949c664c..c8ecfdba91a786424a7f20d0271246eb45d93627 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,7 @@ - [hot-plugged drives](#hot-plugged-drives)
- [tmux configuration](#tmux-configuration)
- [BSD terminal issue](#bsd-terminal-issue)
- [restrict file open](#restrict-file-open)
+ - [restrict 0-byte files](#restrict-0-byte-files)
- [Why fork?](#why-fork)
- [Mentions](#mentions)
- [Developers](#developers)
@@ -531,13 +532,19 @@ #### BSD terminal issue
By default in OpenBSD & FreeBSD, `stty` maps ^Y to `DSUSP`. This means that typing ^Y will suspend `nnn` as if you typed ^Z (you can bring `nnn` back to the foreground by issuing `fg`) instead of entering multi-copy mode. You can check this with `stty -a`. If it includes the text `dsusp = ^Y`, issuing `stty dsusp undef` will disable this `DSUSP` and let `nnn` receive the ^Y instead.
-#### Restrict file open
+#### restrict file open
In order to disable opening files on accidental navigation key (→ or l) press:
export DISABLE_FILE_OPEN_ON_NAV=1
Use Enter to open files.
+
+#### restrict 0-byte files
+
+Restrict opening 0-byte files due to [unexpected behaviour](https://github.com/jarun/nnn/issues/187); use _edit_ or _open with_ to open the file.
+
+ export NNN_RESTRICT_0B=1
#### WHY FORK?
diff --git a/nnn.1 b/nnn.1
index f78cd9960a7f297a2d3473f1576a8998fd2f0bd8..4a824a1f39482ac937b6e321b1c0062a7badda6d 100644
--- a/nnn.1
+++ b/nnn.1
@@ -309,6 +309,11 @@ \fBDISABLE_FILE_OPEN_ON_NAV:\fR disable file open on \fBRight\fR or \fBl\fR keys (\fBEnter\fR opens files).
.Bd -literal
export DISABLE_FILE_OPEN_ON_NAV=1
.Ed
+.Pp
+\fBNNN_RESTRICT_0B:\fR restrict opening 0-byte files due to unexpected behaviour; use \fIedit\fR or \fIopen with\fR to open the file.
+.Bd -literal
+ export NNN_RESTRICT_0B=1
+.Ed
.Sh KNOWN ISSUES
If you are using urxvt you might have to set backspace key to DEC.
.Sh AUTHORS
diff --git a/src/nnn.c b/src/nnn.c
index 50c9b9de2bc3b9d501b678659fb45480e066c995..1cdaa569d7d37a295befa4891034374699fca6a6 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -260,7 +260,7 @@ uint showcolor : 1; /* Set to show dirs in blue */
uint dircolor : 1; /* Current status of dir color */
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
uint ctxactive : 1; /* Context active or not */
- uint reserved : 10;
+ uint reserved : 9;
/* The following settings are global */
uint curctx : 2; /* Current context number */
uint picker : 1; /* Write selection to user-specified file */
@@ -269,6 +269,7 @@ uint nonavopen : 1; /* Open file on right arrow or `l` */
uint useeditor : 1; /* Use VISUAL to open text files */
uint runscript : 1; /* Choose script to run mode */
uint runctx : 2; /* The context in which script is to be run */
+ uint restrict0b : 1; /* Restrict 0-byte file opening */
} settings;
/* Contexts or workspaces */
@@ -284,7 +285,7 @@
/* GLOBALS */
/* Configuration, contexts */
-static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0};
+static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static context g_ctx[CTX_MAX] __attribute__ ((aligned));
static struct entry *dents;
@@ -2770,6 +2771,11 @@ goto nochange;
continue;
}
+ if (!sb.st_size && cfg.restrict0b) {
+ printmsg("empty: use edit or open with");
+ goto nochange;
+ }
+
/* Invoke desktop opener as last resort */
spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
continue;
@@ -3774,6 +3780,10 @@
/* Disable opening files on right arrow and `l` */
if (getenv("DISABLE_FILE_OPEN_ON_NAV"))
cfg.nonavopen = 1;
+
+ /* Restrict opening of 0-byte files */
+ if (getenv("NNN_RESTRICT_0B"))
+ cfg.restrict0b = 1;
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);