Key B to add bookmarks on the fly

This commit is contained in:
Arun Prakash Jana 2021-08-17 20:28:12 +05:30
parent 0aed67f329
commit 78ea6702f7
No known key found for this signature in database
GPG Key ID: A75979F35C080412
2 changed files with 27 additions and 6 deletions

View File

@ -4918,6 +4918,21 @@ static size_t handle_bookmark(const char *bmark, char *newpath)
return r; 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 * The help string tokens (each line) start with a HEX value
* which indicates the number of spaces to print before the * 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" "5Ret Rt l Open%-20c' First file/match\n"
"9g ^A Top%-21c. Toggle hidden\n" "9g ^A Top%-21c. Toggle hidden\n"
"9G ^E End%-21c+ Toggle auto-advance\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" "a1-4 Context%-11c(Sh)Tab Cycle/new context\n"
"62Esc ^Q Quit%-20cq Quit context\n" "62Esc ^Q Quit%-20cq Quit context\n"
"b^G QuitCD%-18cQ Pick/err, quit\n" "b^G QuitCD%-18cQ Pick/err, quit\n"
@ -6882,8 +6897,8 @@ nochange:
/* SEL_CDLAST: dir pointing to lastdir */ /* SEL_CDLAST: dir pointing to lastdir */
xstrsncpy(newpath, dir, PATH_MAX); // fallthrough xstrsncpy(newpath, dir, PATH_MAX); // fallthrough
case SEL_BOOKMARK: case SEL_BMOPEN:
if (sel == SEL_BOOKMARK) { if (sel == SEL_BMOPEN) {
r = (int)handle_bookmark(mark, newpath); r = (int)handle_bookmark(mark, newpath);
if (r) { if (r) {
printwait(messages[r], &presel); printwait(messages[r], &presel);
@ -6941,6 +6956,9 @@ nochange:
mark = xstrdup(path); mark = xstrdup(path);
printwait(mark, &presel); printwait(mark, &presel);
goto nochange; goto nochange;
case SEL_BMARK:
add_bookmark(path, newpath, &presel);
goto nochange;
case SEL_FLTR: case SEL_FLTR:
if (!ndents) if (!ndents)
goto nochange; goto nochange;

View File

@ -60,7 +60,7 @@ enum action {
SEL_CDBEGIN, SEL_CDBEGIN,
SEL_CDLAST, SEL_CDLAST,
SEL_CDROOT, SEL_CDROOT,
SEL_BOOKMARK, SEL_BMOPEN,
SEL_REMOTE, SEL_REMOTE,
SEL_CYCLE, SEL_CYCLE,
SEL_CYCLER, SEL_CYCLER,
@ -75,6 +75,7 @@ enum action {
SEL_CTX8, SEL_CTX8,
#endif #endif
SEL_MARK, SEL_MARK,
SEL_BMARK,
SEL_FLTR, SEL_FLTR,
SEL_MFLTR, SEL_MFLTR,
SEL_HIDDEN, SEL_HIDDEN,
@ -167,8 +168,8 @@ static struct key bindings[] = {
/* Go to / */ /* Go to / */
{ '`', SEL_CDROOT }, { '`', SEL_CDROOT },
/* Leader key */ /* Leader key */
{ 'b', SEL_BOOKMARK }, { 'b', SEL_BMOPEN },
{ CONTROL('_'), SEL_BOOKMARK }, { CONTROL('_'), SEL_BMOPEN },
/* Connect to server over SSHFS */ /* Connect to server over SSHFS */
{ 'c', SEL_REMOTE }, { 'c', SEL_REMOTE },
/* Cycle contexts in forward direction */ /* Cycle contexts in forward direction */
@ -188,6 +189,8 @@ static struct key bindings[] = {
#endif #endif
/* Mark a path to visit later */ /* Mark a path to visit later */
{ ',', SEL_MARK }, { ',', SEL_MARK },
/* Create a bookmark */
{ 'B', SEL_BMARK },
/* Filter */ /* Filter */
{ '/', SEL_FLTR }, { '/', SEL_FLTR },
/* Toggle filter mode */ /* Toggle filter mode */