]> Sergey Matveev's repositories - nnn.git/commitdiff
Key B to add bookmarks on the fly
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 17 Aug 2021 14:58:12 +0000 (20:28 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 17 Aug 2021 15:23:54 +0000 (20:53 +0530)
src/nnn.c
src/nnn.h

index 9ca979bb3bbe3198ae2f6ba76ba6f147cdece91d..3b5f1275b17b6a82cc8b7731ff44703c120416d9 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4918,6 +4918,21 @@ static size_t handle_bookmark(const char *bmark, char *newpath)
        return r;
 }
 
+static void add_bookmark(char *path, char *newpath, int *presel)
+{
+       char *dir = xbasename(path);
+
+       dir = xreadline(dir[0] ? dir : NULL, "name: ");
+       if (dir && *dir) {
+               size_t r = mkpath(cfgpath, toks[TOK_BM], newpath);
+
+               newpath[r - 1] = '/';
+               xstrsncpy(newpath + r, dir, PATH_MAX - r);
+               printwait((symlink(path, newpath) == -1) ? strerror(errno) : newpath, presel);
+       } else
+               printwait(messages[MSG_CANCEL], presel);
+}
+
 /*
  * The help string tokens (each line) start with a HEX value
  * which indicates the number of spaces to print before the
@@ -4938,7 +4953,7 @@ static void show_help(const char *path)
           "5Ret Rt l  Open%-20c'  First file/match\n"
               "9g ^A  Top%-21c.  Toggle hidden\n"
               "9G ^E  End%-21c+  Toggle auto-advance\n"
-                 "c,  Mark CWD%-13cb ^/  Select bookmark\n"
+             "8B (,)  Book(mark)%-11cb ^/  Select bookmark\n"
                "a1-4  Context%-11c(Sh)Tab  Cycle/new context\n"
            "62Esc ^Q  Quit%-20cq  Quit context\n"
                 "b^G  QuitCD%-18cQ  Pick/err, quit\n"
@@ -6882,8 +6897,8 @@ nochange:
 
                        /* SEL_CDLAST: dir pointing to lastdir */
                        xstrsncpy(newpath, dir, PATH_MAX); // fallthrough
-               case SEL_BOOKMARK:
-                       if (sel == SEL_BOOKMARK) {
+               case SEL_BMOPEN:
+                       if (sel == SEL_BMOPEN) {
                                r = (int)handle_bookmark(mark, newpath);
                                if (r) {
                                        printwait(messages[r], &presel);
@@ -6941,6 +6956,9 @@ nochange:
                        mark = xstrdup(path);
                        printwait(mark, &presel);
                        goto nochange;
+               case SEL_BMARK:
+                       add_bookmark(path, newpath, &presel);
+                       goto nochange;
                case SEL_FLTR:
                        if (!ndents)
                                goto nochange;
index 6e934dfaf39d10eba803ee23875afe11a36c67f6..969419b8e56dde90d1ca1b4ba9dccebc481e7099 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -60,7 +60,7 @@ enum action {
        SEL_CDBEGIN,
        SEL_CDLAST,
        SEL_CDROOT,
-       SEL_BOOKMARK,
+       SEL_BMOPEN,
        SEL_REMOTE,
        SEL_CYCLE,
        SEL_CYCLER,
@@ -75,6 +75,7 @@ enum action {
        SEL_CTX8,
 #endif
        SEL_MARK,
+       SEL_BMARK,
        SEL_FLTR,
        SEL_MFLTR,
        SEL_HIDDEN,
@@ -167,8 +168,8 @@ static struct key bindings[] = {
        /* Go to / */
        { '`',            SEL_CDROOT },
        /* Leader key */
-       { 'b',            SEL_BOOKMARK },
-       { CONTROL('_'),   SEL_BOOKMARK },
+       { 'b',            SEL_BMOPEN },
+       { CONTROL('_'),   SEL_BMOPEN },
        /* Connect to server over SSHFS */
        { 'c',            SEL_REMOTE },
        /* Cycle contexts in forward direction */
@@ -188,6 +189,8 @@ static struct key bindings[] = {
 #endif
        /* Mark a path to visit later */
        { ',',            SEL_MARK },
+       /* Create a bookmark */
+       { 'B',            SEL_BMARK },
        /* Filter */
        { '/',            SEL_FLTR },
        /* Toggle filter mode */