option -p: pick last selected entry if no explicit select

This commit is contained in:
Arun Prakash Jana 2018-11-24 00:40:03 +05:30
parent 6853487109
commit fb64e7e2dd
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -436,6 +436,7 @@ static void printerr(int linenum)
fprintf(stderr, "line %d: (%d) %s\n", linenum, errno, strerror(errno));
if (!cfg.picker && g_cppath[0])
unlink(g_cppath);
free(pcopybuf);
exit(1);
}
@ -3329,34 +3330,6 @@ nochange:
case SEL_LOCK:
spawn(utils[LOCKER], NULL, NULL, NULL, F_NORMAL | F_SIGINT);
break;
case SEL_QUITCTX:
{
uint iter = 1;
r = cfg.curctx;
while (iter < MAX_CTX) {
(r == MAX_CTX - 1) ? (r = 0) : ++r;
if (g_ctx[r].c_cfg.ctxactive) {
g_ctx[cfg.curctx].c_cfg.ctxactive = 0;
/* Switch to next active context */
path = g_ctx[r].c_path;
ipath = g_ctx[r].c_init;
lastdir = g_ctx[r].c_last;
lastname = g_ctx[r].c_name;
cfg = g_ctx[r].c_cfg;
hfltr = g_ctx[r].c_fltr;
cfg.curctx = r;
setdirwatch();
goto begin;
}
++iter;
}
dentfree(dents);
return;
}
case SEL_CDQUIT: // fallthrough
case SEL_QUIT:
for (r = 0; r < MAX_CTX; ++r)
@ -3381,6 +3354,37 @@ nochange:
fprintf(fp, "cd \"%s\"", path);
fclose(fp);
}
} // fallthrough
case SEL_QUITCTX:
if (sel == SEL_QUITCTX) {
uint iter = 1;
r = cfg.curctx;
while (iter < MAX_CTX) {
(r == MAX_CTX - 1) ? (r = 0) : ++r;
if (g_ctx[r].c_cfg.ctxactive) {
g_ctx[cfg.curctx].c_cfg.ctxactive = 0;
/* Switch to next active context */
path = g_ctx[r].c_path;
ipath = g_ctx[r].c_init;
lastdir = g_ctx[r].c_last;
lastname = g_ctx[r].c_name;
cfg = g_ctx[r].c_cfg;
hfltr = g_ctx[r].c_fltr;
cfg.curctx = r;
setdirwatch();
goto begin;
}
++iter;
}
}
if (cfg.picker && copybufpos == 0 && ndents) {
r = mkpath(path, dents[cur].name, newpath, PATH_MAX);
appendfpath(newpath, r);
writecp(newpath, r - 1);
}
dentfree(dents);
@ -3582,11 +3586,17 @@ int main(int argc, char *argv[])
exitcurses();
if (cfg.pickraw) {
if (copybufpos) {
opt = write(1, pcopybuf, copybufpos - 1);
DPRINTF_D(opt);
if (opt != (int)(copybufpos - 1))
fprintf(stderr, "%s\n", strerror(errno));
}
} else if (!cfg.picker && g_cppath[0])
unlink(g_cppath);
/* Free the copy buffer */
free(pcopybuf);
#ifdef LINUX_INOTIFY
/* Shutdown inotify */
if (inotify_wd >= 0)