return r;
}
+/* ctx is absolute: 1 to 4, + for smart context */
+static void set_smart_ctx(int ctx, char *nextpath, char **path, char **lastname, char **lastdir)
+{
+ if (ctx == '+') /* Get smart context */
+ ctx = (int)(get_free_ctx() + 1);
+
+ if (ctx == 0 || ctx == cfg.curctx + 1) { /* Same context */
+ /* Mark current directory */
+ free(mark);
+ mark = xstrdup(*path);
+
+ xstrsncpy(*lastdir, *path, PATH_MAX);
+ xstrsncpy(*path, nextpath, PATH_MAX);
+ } else { /* New context */
+ --ctx;
+ /* Deactivate the new context and build from scratch */
+ g_ctx[ctx].c_cfg.ctxactive = 0;
+ savecurctx(&cfg, nextpath, pdents[cur].name, ctx);
+ *path = g_ctx[ctx].c_path;
+ *lastdir = g_ctx[ctx].c_last;
+ *lastname = g_ctx[ctx].c_name;
+ }
+}
+
/*
* Gets only a single line (that's what we need for now) or shows full command output in pager.
* Uses g_buf internally.
}
/* List or extract archive */
-static bool handle_archive(char *fpath, char op)
+static bool handle_archive(char *fpath /* in-out param */, char op)
{
char arg[] = "-tvf"; /* options for tar/bsdtar to list files */
char *util, *outdir;
printwarn(NULL);
return FALSE;
}
+ outdir = realpath(".", NULL);
x_to = TRUE;
}
}
else /* list */
get_output(util, arg, fpath, NULL, TRUE, TRUE);
- if (x_to && (chdir(xdirname(fpath)) == -1)) {
- printwarn(NULL);
- return FALSE;
+ if (x_to) {
+ if (chdir(xdirname(fpath)) == -1) {
+ printwarn(NULL);
+ return FALSE;
+ }
+ xstrsncpy(fpath, outdir, PATH_MAX);
+ free(outdir);
}
return TRUE;
static void readpipe(int fd, char **path, char **lastname, char **lastdir)
{
- int r;
char ctx, *nextpath = NULL;
if (read_nointr(fd, g_buf, 1) != 1)
g_state.picked = 1;
}
- if (nextpath) {
- if (ctx == 0 || ctx == cfg.curctx + 1) { /* Same context */
- xstrsncpy(*lastdir, *path, PATH_MAX);
- xstrsncpy(*path, nextpath, PATH_MAX);
- DPRINTF_S(*path);
- } else { /* New context */
- r = ctx - 1;
- /* Deactivate the new context and build from scratch */
- g_ctx[r].c_cfg.ctxactive = 0;
- savecurctx(&cfg, nextpath, pdents[cur].name, r);
- *path = g_ctx[r].c_path;
- *lastdir = g_ctx[r].c_last;
- *lastname = g_ctx[r].c_name;
- }
- }
+ if (nextpath)
+ set_smart_ctx(ctx, nextpath, path, lastname, lastdir);
}
static bool run_selected_plugin(char **path, const char *file, char *runfile, char **lastname, char **lastdir)
statusbar(path);
goto nochange;
}
- copycurname();
- clearfilter();
- goto begin;
}
- if (r == 'm') {
- if (!archive_mount(newpath)) {
- presel = MSGWAIT;
- goto nochange;
- }
-
- /* Mark current directory */
- free(mark);
- mark = xstrdup(path);
+ if ((r == 'm') && !archive_mount(newpath)) {
+ presel = MSGWAIT;
+ goto nochange;
+ }
- cdprep(lastdir, lastname, path, newpath)
- ? (presel = FILTER) : (watch = TRUE);
+ if (r == 'x' || r == 'm') {
+ set_smart_ctx('+', newpath, &path, &lastname, &lastdir);
+ clearfilter();
goto begin;
}
if (strcmp(path, newpath) == 0)
break;
- } // fallthrough
- case SEL_REMOTE:
- if (sel == SEL_REMOTE && !remote_mount(newpath)) {
- presel = MSGWAIT;
- goto nochange;
}
- /* Mark current directory */
- free(mark);
- mark = xstrdup(path);
-
/* In list mode, retain the last file name to highlight it, if possible */
cdprep(lastdir, listpath && sel == SEL_CDLAST ? NULL : lastname, path, newpath)
? (presel = FILTER) : (watch = TRUE);
goto begin;
+ case SEL_REMOTE:
+ if ((sel == SEL_REMOTE) && !remote_mount(newpath)) {
+ presel = MSGWAIT;
+ goto nochange;
+ }
+
+ set_smart_ctx('+', newpath, &path, &lastname, &lastdir);
+ clearfilter();
+ goto begin;
case SEL_CYCLE: // fallthrough
case SEL_CYCLER: // fallthrough
case SEL_CTX1: // fallthrough