]> Sergey Matveev's repositories - nnn.git/commitdiff
Option to disable file open on Right and `l`
authorArun Prakash Jana <engineerarun@gmail.com>
Mon, 26 Nov 2018 18:54:12 +0000 (00:24 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 26 Nov 2018 20:36:57 +0000 (02:06 +0530)
README.md
nnn.1
src/nnn.c
src/nnn.h

index af946e7d535966c169d59c796cae7ee1eaebbbeb..bd5a0790f74592fa42f7563072b3d1fb78ca9f49 100644 (file)
--- a/README.md
+++ b/README.md
@@ -73,6 +73,7 @@ It runs on Linux, OS X, Raspberry Pi, Cygwin, Linux subsystem for Windows and Te
   - [show hot plugged drives](#show-hot-plugged-drives)
   - [tmux configuration](#tmux-configuration)
   - [BSD terminal issue](#bsd-terminal-issue)
+  - [Disable file open on navigation](#disable-file-open-on-navigation)
 - [Why fork?](#why-fork)
 - [Mentions](#mentions)
 - [Developers](#developers)
@@ -515,6 +516,14 @@ 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.
 
+#### Disable file open on navigation
+
+In order to disable opening files on accidental navigation key (<kbd>→</kbd> or <kbd>l</kbd>) press:
+
+    export DISABLE_FILE_OPEN_ON_NAV=1
+
+To open files with this setting, press <kbd>Enter</kbd>.
+
 #### 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:
diff --git a/nnn.1 b/nnn.1
index aef323fa0df1df31d14fd0b93671f36923afe150..736e1f41f1930b75d6eb6b352662b8d705d5654e 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -317,6 +317,12 @@ for filenames having quote(s) in them.
 .Bd -literal
     export NNN_NO_AUTOSELECT=1
 .Ed
+.Pp
+\fBDISABLE_FILE_OPEN_ON_NAV:\fR Disable file open on \fBRight\fR or \fBl\fR keys. To open
+files, press \fBEnter\fR.
+.Bd -literal
+    export DISABLE_FILE_OPEN_ON_NAV=1
+.Ed
 .Sh KNOWN ISSUES
 If you are using urxvt you might have to set backspace key to DEC.
 .Sh AUTHORS
index 35df72168aa7f9891651cd1db6a2b74a19cc365c..522ba64c0c0b3b91c1cc7d35e96dd43a3d431863 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -261,11 +261,12 @@ typedef struct {
        uint quote      : 1;  /* Copy paths within quotes */
        uint color      : 3;  /* Color code for directories */
        uint ctxactive  : 1;  /* Context active or not */
-       uint reserved   : 11;
+       uint reserved   : 10;
        /* The following settings are global */
        uint curctx     : 2;  /* Current context number */
        uint picker     : 1;  /* Write selection to user-specified file */
        uint pickraw    : 1;  /* Write selection to sdtout before exit */
+       uint nonavopen  : 1;  /* Open file on right arrow or `l` */
 } settings;
 
 /* Contexts or workspaces */
@@ -281,7 +282,7 @@ typedef struct {
 /* GLOBALS */
 
 /* Configuration, contexts */
-static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 4, 1, 0, 0, 0, 0};
+static settings cfg = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0};
 static context g_ctx[MAX_CTX] __attribute__ ((aligned));
 
 static struct entry *dents;
@@ -2040,9 +2041,13 @@ static int show_help(char *path)
        if (getenv("NNN_SCRIPT"))
                dprintf(fd, "NNN_SCRIPT: %s\n", getenv("NNN_SCRIPT"));
        if (getenv("NNN_MULTISCRIPT"))
-               dprintf(fd, "NNN_MULTISCRIPT: %s\n", getenv("NNN_MULTISCRIPT"));
+               dprintf(fd, "NNN_MULTISCRIPT: 1\n");
        if (getenv("NNN_SHOW_HIDDEN"))
-               dprintf(fd, "NNN_SHOW_HIDDEN: %s\n", getenv("NNN_SHOW_HIDDEN"));
+               dprintf(fd, "NNN_SHOW_HIDDEN: 1\n");
+       if (getenv("NNN_NO_AUTOSELECT"))
+               dprintf(fd, "NNN_NO_AUTOSELECT: 1\n");
+       if (getenv("DISABLE_FILE_OPEN_ON_NAV"))
+               dprintf(fd, "DISABLE_FILE_OPEN_ON_NAV: 1\n");
 
        dprintf(fd, "\n");
 
@@ -2574,6 +2579,7 @@ nochange:
 
                        setdirwatch();
                        goto begin;
+               case SEL_NAV_IN: // fallthrough
                case SEL_GOIN:
                        /* Cannot descend in empty directories */
                        if (!ndents)
@@ -2612,6 +2618,10 @@ nochange:
                                goto begin;
                        case S_IFREG:
                        {
+                               /* If open file is disabled on right arrow or `l`, return */
+                               if (cfg.nonavopen && sel == SEL_NAV_IN)
+                                       continue;
+
                                /* If NNN_USE_EDITOR is set,
                                 * open text in EDITOR
                                 */
@@ -3573,6 +3583,10 @@ int main(int argc, char *argv[])
        if (getenv("NNN_NO_AUTOSELECT"))
                cfg.autoselect = 0;
 
+       /* Disable opening files on right arrow and `l` */
+       if (getenv("DISABLE_FILE_OPEN_ON_NAV"))
+               cfg.nonavopen = 1;
+
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
 
index 6802167fc72947ac52d56ca66979c84f5ef6f682..4b13d91881537f3fdf8e0c9cbf111684f77c9ee6 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -38,6 +38,7 @@
 enum action {
        SEL_BACK = 1,
        SEL_GOIN,
+       SEL_NAV_IN,
        SEL_NEXT,
        SEL_PREV,
        SEL_PGDN,
@@ -117,8 +118,8 @@ static struct key bindings[] = {
        /* Inside */
        { KEY_ENTER,      SEL_GOIN,      "",     "" },
        { '\r',           SEL_GOIN,      "",     "" },
-       { KEY_RIGHT,      SEL_GOIN,      "",     "" },
-       { 'l',            SEL_GOIN,      "",     "" },
+       { KEY_RIGHT,      SEL_NAV_IN,    "",     "" },
+       { 'l',            SEL_NAV_IN,    "",     "" },
        /* Next */
        { 'j',            SEL_NEXT,      "",     "" },
        { KEY_DOWN,       SEL_NEXT,      "",     "" },