]> Sergey Matveev's repositories - nnn.git/commitdiff
Support mark a directory
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 20 Aug 2017 11:17:23 +0000 (16:47 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 20 Aug 2017 11:17:23 +0000 (16:47 +0530)
In certain workflows you know you would have revisit a directory. Mark it!

README.md
config.h
nnn.1
nnn.c

index c580bf35e8116219f6e52be2af3e083ec30f8dbe..ab2276d4312c4522d41b51dd9ac6915c10b14982 100644 (file)
--- a/README.md
+++ b/README.md
@@ -203,6 +203,8 @@ Home, g, ^, ^A | Jump to first entry
             ^/ | Open desktop search tool
              . | Toggle hide .dot files
              b | Show bookmark key prompt
+            ^B | Mark current dir
+            ^V | Visit marked dir
              c | Show change dir prompt
              d | Toggle detail view
              D | Show current file details
index 45f036ee34fd9fa658dbd507863c9201914e3f6b..275de033c56469c6f5aae326fc0accb04c2e1dfd 100644 (file)
--- a/config.h
+++ b/config.h
@@ -21,6 +21,8 @@ enum action {
        SEL_CDBEGIN,
        SEL_CDLAST,
        SEL_CDBM,
+       SEL_MARK,
+       SEL_VISIT,
        SEL_TOGGLEDOT,
        SEL_DETAIL,
        SEL_STATS,
@@ -111,6 +113,10 @@ static struct key bindings[] = {
        { '-',            SEL_CDLAST,    "",     "" },
        /* Change dir using bookmark */
        { 'b',            SEL_CDBM,      "",     "" },
+       /* Mark a path to visit later */
+       { CONTROL('B'),   SEL_MARK,      "",     "" },
+       /* Visit marked directory */
+       { CONTROL('V'),   SEL_VISIT,     "",     "" },
        /* Toggle hide .dot files */
        { '.',            SEL_TOGGLEDOT, "",     "" },
        /* Detailed listing */
@@ -129,6 +135,7 @@ static struct key bindings[] = {
        { 'S',            SEL_BSIZE,     "",     "" },
        /* Toggle sort by time */
        { 't',            SEL_MTIME,     "",     "" },
+       /* Redraw window */
        { CONTROL('L'),   SEL_REDRAW,    "",     "" },
        { KEY_F(2),       SEL_REDRAW,    "",     "" },
        /* Copy currently selected file path */
diff --git a/nnn.1 b/nnn.1
index 562041d74f066198a7d5e5470880339b529bcc87..7cece0d151aed4b228d4f90936a3b8bbbc9576b0 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -61,6 +61,10 @@ Search directory in desktop search tool
 Toggle hide .dot files
 .It Ic b
 Show bookmark key prompt
+.It Ic ^B
+Mark current dir
+.It Ic ^V
+Visit marked dir
 .It Ic c
 Show change dir prompt
 .It Ic d
diff --git a/nnn.c b/nnn.c
index 17506fd5f35d5a83932984f5076a2b262660a57a..2991482f61ab42223968f11e1f2e22b8203046d8 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -1500,6 +1500,8 @@ Home, g, ^, ^A | Jump to first entry\n\
             ^/ | Open desktop search tool\n\
              . | Toggle hide .dot files\n\
              b | Show bookmark key prompt\n\
+            ^B | Mark current dir\n\
+            ^V | Visit marked dir\n\
              c | Show change dir prompt\n\
              d | Toggle detail view\n\
              D | Show current file details\n\
@@ -1854,9 +1856,8 @@ redraw(char *path)
 static void
 browse(char *ipath, char *ifilter)
 {
-       char path[PATH_MAX], oldpath[PATH_MAX], newpath[PATH_MAX];
-       char lastdir[PATH_MAX];
-       char fltr[LINE_MAX];
+       static char path[PATH_MAX], oldpath[PATH_MAX], newpath[PATH_MAX], lastdir[PATH_MAX], mark[PATH_MAX];
+       static char fltr[LINE_MAX];
        char *dir, *tmp, *run, *env, *tgt = NULL;
        struct stat sb;
        int r, fd, presel;
@@ -1864,9 +1865,7 @@ browse(char *ipath, char *ifilter)
 
        xstrlcpy(path, ipath, PATH_MAX);
        xstrlcpy(fltr, ifilter, LINE_MAX);
-       oldpath[0] = '\0';
-       newpath[0] = '\0';
-       lastdir[0] = '\0'; /* Can't move back from initial directory */
+       oldpath[0] = newpath[0] = lastdir[0] = mark[0] = '\0';
 
        if (cfg.filtermode)
                presel = FILTER;
@@ -2228,18 +2227,27 @@ nochange:
                                presel = FILTER;
                        tgt = NULL;
                        goto begin;
-               case SEL_CDLAST:
-                       if (lastdir[0] == '\0') {
-                               printmsg("Hit end of history...");
+               case SEL_CDLAST: // fallthrough
+               case SEL_VISIT:
+                       if (sel == SEL_VISIT) {
+                               if (xstrcmp(mark, path) == 0)
+                                       break;
+
+                               tmp = mark;
+                       } else
+                               tmp = lastdir;
+
+                       if (tmp[0] == '\0') {
+                               printmsg("Not set...");
                                goto nochange;
                        }
 
-                       if (access(lastdir, R_OK) == -1) {
+                       if (access(tmp, R_OK) == -1) {
                                printwarn();
                                goto nochange;
                        }
 
-                       xstrlcpy(newpath, lastdir, PATH_MAX);
+                       xstrlcpy(newpath, tmp, PATH_MAX);
                        xstrlcpy(lastdir, path, PATH_MAX);
                        xstrlcpy(path, newpath, PATH_MAX);
                        oldpath[0] = '\0';
@@ -2309,6 +2317,10 @@ nochange:
                        if (cfg.filtermode)
                                presel = FILTER;
                        goto begin;
+               case SEL_MARK:
+                       xstrlcpy(mark, path, PATH_MAX);
+                       printmsg(mark);
+                       goto nochange;
                case SEL_TOGGLEDOT:
                        cfg.showhidden ^= 1;
                        initfilter(cfg.showhidden, &ifilter);
@@ -2468,8 +2480,8 @@ Webpage: https://github.com/jarun/nnn\n", VERSION);
 int
 main(int argc, char *argv[])
 {
-       char cwd[PATH_MAX], *ipath;
-       char *ifilter, *bmstr;
+       static char cwd[PATH_MAX];
+       char *ipath, *ifilter, *bmstr;
        int opt;
 
        /* Confirm we are in a terminal */