]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #350: cd on quit if NNN_TMPFILE is set
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 11 Oct 2019 17:49:25 +0000 (23:19 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 11 Oct 2019 17:49:25 +0000 (23:19 +0530)
misc/quitcd/quitcd.bash
misc/quitcd/quitcd.csh
misc/quitcd/quitcd.fish
misc/quitcd/quitcd.zsh
nnn.1
src/nnn.c

index e303b4cdf70ef14e97aa48762eaa2001d8afa319..a26395dbec1311ed58e2567c301b531c0f936232 100644 (file)
@@ -1,5 +1,7 @@
 n()
 {
+    # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
+    # To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
     export NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd
 
     nnn "$@"
index 9ea952d2e774f9c75b96a51120dabd947e178404..206e620a06e03c53164b756a9d90d98b1e590a95 100644 (file)
@@ -1,3 +1,7 @@
 # NOTE: set NNN_TMPFILE correctly if you use 'XDG_CONFIG_HOME'
+
+# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
+# To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
 set NNN_TMPFILE=~/.config/nnn/.lastd
+
 alias n 'nnn; source "$NNN_TMPFILE"; rm "$NNN_TMPFILE"'
index f2a54e8ab9ce8013d6060d9e2294bf8cea2c5455..4117cc5148183ee92bc658e7b9feeeebbc974a63 100644 (file)
@@ -3,6 +3,8 @@
 # or, add the lines to the 'config.fish' file.
 
 function n --description 'support nnn quit and change directory'
+    # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
+    # To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
     if test -n "$XDG_CONFIG_HOME"
         set -x NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd"
     else
index c55b321d505e4ab9cfe05905b99286b3f5a76dd4..9259e4a69f92039e489f6e2cbecd54dc30b2281c 100644 (file)
@@ -1,5 +1,7 @@
 n()
 {
+    # The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
+    # To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
     export NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd
 
     nnn "$@"
diff --git a/nnn.1 b/nnn.1
index bdbe57063091c2bf10f5fc718379a529e6aab728..24b5eae74c1a858fb8efcead05d3f64ca17e12e2 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -95,11 +95,6 @@ supports the following options:
 uses \fIxdg-open\fR (on Linux) and \fIopen(1)\fR (on macOS) as the desktop opener.
 .Pp
 There is no configuration file. Associated files are stored in \fB${XDG_CONFIG_HOME:-$HOME/.config}/nnn/\fR. Settings work on environment variables. See ENVIRONMENT section below.
-.Pp
-Configuring
-.Nm
-to change to the last visited directory on quit requires shell integration in a
-few easy steps. Look up NNN_TMPFILE in the ENVIRONMENT section below.
 .Sh CONTEXTS
 Contexts serve the purpose of exploring multiple directories simultaneously. 4 contexts
 are available. The status of the contexts are shown in the top left corner:
index 78e4029a5b81d21d7f1815dbcd3379a3ca84c924..afbda1fcd104ebdc364e9f3fe241d64b732ee049 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4603,9 +4603,42 @@ nochange:
                                }
 
                        if (!(r == CTX_MAX || r == '\r'))
-                               break;
+                               break; // fallthrough
+               case SEL_QUITCTX:
+                       if (sel == SEL_QUITCTX) {
+                               fd = cfg.curctx; /* fd used as tmp var */
+                               for (r = (fd + 1) & ~CTX_MAX;
+                                    (r != fd) && !g_ctx[r].c_cfg.ctxactive;
+                                    r = ((r + 1) & ~CTX_MAX)) {
+                               };
+
+                               if (r != fd) {
+                                       bool selmode = cfg.selmode ? TRUE : FALSE;
+
+                                       g_ctx[fd].c_cfg.ctxactive = 0;
+
+                                       /* Switch to next active context */
+                                       path = g_ctx[r].c_path;
+                                       lastdir = g_ctx[r].c_last;
+                                       lastname = g_ctx[r].c_name;
+
+                                       /* Switch light/detail mode */
+                                       if (cfg.showdetail != g_ctx[r].c_cfg.showdetail)
+                                               /* Set the reverse */
+                                               printptr = cfg.showdetail ?
+                                                               &printent : &printent_long;
+
+                                       cfg = g_ctx[r].c_cfg;
+
+                                       /* Continue selection mode */
+                                       cfg.selmode = selmode;
+                                       cfg.curctx = r;
+                                       setdirwatch();
+                                       goto begin;
+                               }
+                       }
 
-                       if (sel == SEL_QUITCD) {
+                       if (sel == SEL_QUITCD || getenv("NNN_TMPFILE")) {
                                /* In vim picker mode, clear selection and exit */
                                if (cfg.picker) {
                                        /* Picker mode: reset buffer or clear file */
@@ -4617,37 +4650,6 @@ nochange:
                                }
                        }
                        return;
-               case SEL_QUITCTX:
-                       fd = cfg.curctx; /* fd used as tmp var */
-                       for (r = (fd + 1) & ~CTX_MAX;
-                            (r != fd) && !g_ctx[r].c_cfg.ctxactive;
-                            r = ((r + 1) & ~CTX_MAX)) {
-                       };
-
-                       if (r != fd) {
-                               bool selmode = cfg.selmode ? TRUE : FALSE;
-
-                               g_ctx[fd].c_cfg.ctxactive = 0;
-
-                               /* Switch to next active context */
-                               path = g_ctx[r].c_path;
-                               lastdir = g_ctx[r].c_last;
-                               lastname = g_ctx[r].c_name;
-
-                               /* Switch light/detail mode */
-                               if (cfg.showdetail != g_ctx[r].c_cfg.showdetail)
-                                       /* Set the reverse */
-                                       printptr = cfg.showdetail ? &printent : &printent_long;
-
-                               cfg = g_ctx[r].c_cfg;
-
-                               /* Continue selection mode */
-                               cfg.selmode = selmode;
-                               cfg.curctx = r;
-                               setdirwatch();
-                               goto begin;
-                       }
-                       return;
                default:
                        if (xlines != LINES || xcols != COLS) {
                                idle = 0;