From 8d83af811fa257a00ce93ce6591d59ee958ad539 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 28 May 2022 05:54:55 +0530 Subject: [PATCH] Fix #1369: open target of symlinked bookmark --- nnn.1 | 13 +++++++++---- src/nnn.c | 14 +++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/nnn.1 b/nnn.1 index 35df524d..0ce59844 100644 --- 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 diff --git a/src/nnn.c b/src/nnn.c index 21b331b4..4de7d70b 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -178,6 +178,8 @@ #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 */