]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #1369: open target of symlinked bookmark
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 28 May 2022 00:24:55 +0000 (05:54 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 28 May 2022 00:24:55 +0000 (05:54 +0530)
nnn.1
src/nnn.c

diff --git a/nnn.1 b/nnn.1
index 35df524d524c03addf615d5a9fec00dee557f2f6..0ce598441c8b3d9276e98ada7e5338de935ea303 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -351,10 +351,15 @@ There are 2 ways (can be used together) to manage bookmarks.
 (1) Bookmark keys: See \fINNN_BMS\fR under \fIENVIORNMENT\fR section on how to
     set bookmark keys.
 .Pp
-(2) Symlinked bookmarks: Symlinked bookmarks can be created at runtime
-    with the \fIB\fR key. They can also be manually created by adding symlinks
-    to bookmarked locations under the bookmarks directory in the nnn config
-    directory (~/.config/nnn/bookmarks).
+(2) Symlinked bookmarks: A symlinked bookmark to the current directory can be
+    created with the \fIB\fR key.
+    Add prefix \fBn_\fR to the names to open the targets instead of the symlinks.
+
+    Symlinks can also be created manually under the "bookmarks" directory in
+    the nnn config directory (~/.config/nnn/bookmarks).
+
+    Pressing 'Enter' at the bookmarks prompt takes to this directory.
+    If \fINNN_BMS\fR is not set, it happens directly on select bookmark key.
 .Pp
 Pressing \fIb\fR will list all the bookmark keys set in NNN_BMS. Pressing
 \fIEnter\fR at this prompt will take to the symlink bookmark directory, if
index 21b331b4b221740ac0a0db78d17a72ff005d7f49..4de7d70b0509065149a4d0cde0783845ebdad12d 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
 #define MSGWAIT         '$'
 #define SELECT          ' '
 #define PROMPT          ">>> "
+#define BM_PREFIX       "n_"
+#define BM_PREFIX_LEN   (sizeof BM_PREFIX - 1)
 #define REGEX_MAX       48
 #define ENTRY_INCR      64 /* Number of dir 'entry' structures to allocate per shot */
 #define NAMEBUF_INCR    0x800 /* 64 dir entries at once, avg. 32 chars per file name = 64*32B = 2KB */
@@ -638,6 +640,7 @@ static char * const utils[] = {
 #define MSG_INVALID_KEY  40
 #define MSG_NOCHANGE     41
 #define MSG_DIR_CHANGED  42
+#define MSG_BM_NAME      43
 
 static const char * const messages[] = {
        "",
@@ -672,7 +675,7 @@ static const char * const messages[] = {
        "too few cols!",
        "'s'shfs / 'r'clone?",
        "refresh if slow",
-       "app name: ",
+       "app: ",
        "'o'pen / e'x'tract / 'l's / 'm'nt?",
        "keys:",
        "invalid regex",
@@ -683,6 +686,7 @@ static const char * const messages[] = {
        "invalid key",
        "unchanged",
        "dir changed, range sel off",
+       "name (prefix n_ to identify): ",
 };
 
 /* Supported configuration environment variables */
@@ -4998,7 +5002,7 @@ static void add_bookmark(char *path, char *newpath, int *presel)
 {
        char *dir = xbasename(path);
 
-       dir = xreadline(dir[0] ? dir : NULL, "name: ");
+       dir = xreadline(dir[0] ? dir : NULL, messages[MSG_BM_NAME]);
        if (dir && *dir) {
                size_t r = mkpath(cfgpath, toks[TOK_BM], newpath);
 
@@ -6902,7 +6906,11 @@ nochange:
                        }
 
                        pent = &pdents[cur];
-                       mkpath(path, pent->name, newpath);
+                       r = FALSE;
+                       /* Check if it's a symlinked boookmark */
+                       (S_ISLNK(pent->mode) && is_prefix(pent->name, BM_PREFIX, BM_PREFIX_LEN))
+                               ? (realpath(pent->name, newpath) && xstrsncpy(path, lastdir, PATH_MAX))
+                               : mkpath(path, pent->name, newpath);
                        DPRINTF_S(newpath);
 
                        /* Visit directory */