Fix #1369: open target of symlinked bookmark

This commit is contained in:
Arun Prakash Jana 2022-05-28 05:54:55 +05:30
parent ec076f5886
commit 8d83af811f
No known key found for this signature in database
GPG Key ID: A75979F35C080412
2 changed files with 20 additions and 7 deletions

13
nnn.1
View File

@ -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

View File

@ -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 */