mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Fix #187
It seems the behaviour of the default opener (xdg-open) varies across platforms and environments. Details are documented in the issue. To prevent an empty file from being accidentally opened leading to unexpected behaviour, we are adding a guard with the message that the empty file should be opened using edit or open option.
This commit is contained in:
parent
625f2f8830
commit
5df41255b2
|
@ -80,6 +80,7 @@ We need contributors. Please visit the [ToDo list](https://github.com/jarun/nnn/
|
||||||
- [tmux configuration](#tmux-configuration)
|
- [tmux configuration](#tmux-configuration)
|
||||||
- [BSD terminal issue](#bsd-terminal-issue)
|
- [BSD terminal issue](#bsd-terminal-issue)
|
||||||
- [restrict file open](#restrict-file-open)
|
- [restrict file open](#restrict-file-open)
|
||||||
|
- [restrict 0-byte files](#restrict-0-byte-files)
|
||||||
- [Why fork?](#why-fork)
|
- [Why fork?](#why-fork)
|
||||||
- [Mentions](#mentions)
|
- [Mentions](#mentions)
|
||||||
- [Developers](#developers)
|
- [Developers](#developers)
|
||||||
|
@ -531,7 +532,7 @@ Enable volume management in your DE file manager and set removable drives or med
|
||||||
|
|
||||||
By default in OpenBSD & FreeBSD, `stty` maps <kbd>^Y</kbd> to `DSUSP`. This means that typing <kbd>^Y</kbd> will suspend `nnn` as if you typed <kbd>^Z</kbd> (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 <kbd>^Y</kbd> instead.
|
By default in OpenBSD & FreeBSD, `stty` maps <kbd>^Y</kbd> to `DSUSP`. This means that typing <kbd>^Y</kbd> will suspend `nnn` as if you typed <kbd>^Z</kbd> (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 <kbd>^Y</kbd> instead.
|
||||||
|
|
||||||
#### Restrict file open
|
#### restrict file open
|
||||||
|
|
||||||
In order to disable opening files on accidental navigation key (<kbd>→</kbd> or <kbd>l</kbd>) press:
|
In order to disable opening files on accidental navigation key (<kbd>→</kbd> or <kbd>l</kbd>) press:
|
||||||
|
|
||||||
|
@ -539,6 +540,12 @@ In order to disable opening files on accidental navigation key (<kbd>→</kbd> o
|
||||||
|
|
||||||
Use <kbd>Enter</kbd> to open files.
|
Use <kbd>Enter</kbd> 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?
|
#### WHY FORK?
|
||||||
|
|
||||||
`nnn` was initially forked from [noice](http://git.2f30.org/noice/) but is significantly [different](https://github.com/jarun/nnn/wiki/nnn-vs.-noice) today. I chose to fork because:
|
`nnn` was initially forked from [noice](http://git.2f30.org/noice/) but is significantly [different](https://github.com/jarun/nnn/wiki/nnn-vs.-noice) today. I chose to fork because:
|
||||||
|
|
5
nnn.1
5
nnn.1
|
@ -309,6 +309,11 @@ files.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
export DISABLE_FILE_OPEN_ON_NAV=1
|
export DISABLE_FILE_OPEN_ON_NAV=1
|
||||||
.Ed
|
.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
|
.Sh KNOWN ISSUES
|
||||||
If you are using urxvt you might have to set backspace key to DEC.
|
If you are using urxvt you might have to set backspace key to DEC.
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
|
|
14
src/nnn.c
14
src/nnn.c
|
@ -260,7 +260,7 @@ typedef struct {
|
||||||
uint dircolor : 1; /* Current status of dir color */
|
uint dircolor : 1; /* Current status of dir color */
|
||||||
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
|
uint metaviewer : 1; /* Index of metadata viewer in utils[] */
|
||||||
uint ctxactive : 1; /* Context active or not */
|
uint ctxactive : 1; /* Context active or not */
|
||||||
uint reserved : 10;
|
uint reserved : 9;
|
||||||
/* The following settings are global */
|
/* The following settings are global */
|
||||||
uint curctx : 2; /* Current context number */
|
uint curctx : 2; /* Current context number */
|
||||||
uint picker : 1; /* Write selection to user-specified file */
|
uint picker : 1; /* Write selection to user-specified file */
|
||||||
|
@ -269,6 +269,7 @@ typedef struct {
|
||||||
uint useeditor : 1; /* Use VISUAL to open text files */
|
uint useeditor : 1; /* Use VISUAL to open text files */
|
||||||
uint runscript : 1; /* Choose script to run mode */
|
uint runscript : 1; /* Choose script to run mode */
|
||||||
uint runctx : 2; /* The context in which script is to be run */
|
uint runctx : 2; /* The context in which script is to be run */
|
||||||
|
uint restrict0b : 1; /* Restrict 0-byte file opening */
|
||||||
} settings;
|
} settings;
|
||||||
|
|
||||||
/* Contexts or workspaces */
|
/* Contexts or workspaces */
|
||||||
|
@ -284,7 +285,7 @@ typedef struct {
|
||||||
/* GLOBALS */
|
/* GLOBALS */
|
||||||
|
|
||||||
/* Configuration, contexts */
|
/* 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 context g_ctx[CTX_MAX] __attribute__ ((aligned));
|
||||||
|
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
|
@ -2770,6 +2771,11 @@ nochange:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!sb.st_size && cfg.restrict0b) {
|
||||||
|
printmsg("empty: use edit or open with");
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
|
||||||
/* Invoke desktop opener as last resort */
|
/* Invoke desktop opener as last resort */
|
||||||
spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
|
spawn(utils[OPENER], newpath, NULL, NULL, F_NOWAIT | F_NOTRACE);
|
||||||
continue;
|
continue;
|
||||||
|
@ -3775,6 +3781,10 @@ int main(int argc, char *argv[])
|
||||||
if (getenv("DISABLE_FILE_OPEN_ON_NAV"))
|
if (getenv("DISABLE_FILE_OPEN_ON_NAV"))
|
||||||
cfg.nonavopen = 1;
|
cfg.nonavopen = 1;
|
||||||
|
|
||||||
|
/* Restrict opening of 0-byte files */
|
||||||
|
if (getenv("NNN_RESTRICT_0B"))
|
||||||
|
cfg.restrict0b = 1;
|
||||||
|
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue