Simplify and preprocess archive handling

This commit is contained in:
Arun Prakash Jana 2020-08-14 08:20:01 +05:30
parent fbd5e77ec1
commit 9459b15672
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 20 additions and 14 deletions

4
nnn.1
View file

@ -455,9 +455,9 @@ separated by \fI;\fR:
If xterm 256 colors aren't supported, earlier colorscheme will be used. If xterm 256 colors aren't supported, earlier colorscheme will be used.
.Ed .Ed
.Pp .Pp
\fBNNN_ARCHIVE:\fR archive types to be handled silently (default: bzip2, (g)zip, tar). \fBNNN_ARCHIVE:\fR archive extensions to be handled silently (default: bzip2, (g)zip, tar).
.Bd -literal .Bd -literal
export NNN_ARCHIVE="\\\\.(7z|bz2|gz|tar|tgz|zip)$" export NNN_ARCHIVE="(7z|bz2|gz|tar|tgz|zip)$"
NOTE: Non-default formats may require a third-party utility. NOTE: Non-default formats may require a third-party utility.
.Ed .Ed

View file

@ -663,7 +663,7 @@ static const char * const patterns[] = {
"sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s", "sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s",
"sed 's|^\\([^#/][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' " "sed 's|^\\([^#/][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' "
"%s | tr '\\n' '\\0' | xargs -0 -n2 sh -c '%s \"$0\" \"$@\" < /dev/tty'", "%s | tr '\\n' '\\0' | xargs -0 -n2 sh -c '%s \"$0\" \"$@\" < /dev/tty'",
"\\.(bz|bz2|gz|tar|taz|tbz|tbz2|tgz|z|zip)$", "(bz|bz2|gz|tar|taz|tbz|tbz2|tgz|z|zip)$",
"sed -i 's|^%s\\(.*\\)$|%s\\1|' %s", "sed -i 's|^%s\\(.*\\)$|%s\\1|' %s",
}; };
@ -5587,6 +5587,7 @@ static bool browse(char *ipath, const char *session, int pkey)
char rundir[PATH_MAX] __attribute__ ((aligned)); char rundir[PATH_MAX] __attribute__ ((aligned));
char runfile[NAME_MAX + 1] __attribute__ ((aligned)); char runfile[NAME_MAX + 1] __attribute__ ((aligned));
char *path, *lastdir, *lastname, *dir, *tmp; char *path, *lastdir, *lastname, *dir, *tmp;
pEntry pent;
enum action sel; enum action sel;
struct stat sb; struct stat sb;
int r = -1, presel, selstartid = 0, selendid = 0; int r = -1, presel, selstartid = 0, selendid = 0;
@ -5863,11 +5864,12 @@ nochange:
if (!ndents) if (!ndents)
goto begin; goto begin;
mkpath(path, pdents[cur].name, newpath); pent = &pdents[cur];
mkpath(path, pent->name, newpath);
DPRINTF_S(newpath); DPRINTF_S(newpath);
/* Visit directory */ /* Visit directory */
if (pdents[cur].flags & DIR_OR_LINK_TO_DIR) { if (pent->flags & DIR_OR_LINK_TO_DIR) {
if (chdir(newpath) == -1) { if (chdir(newpath) == -1) {
printwarn(&presel); printwarn(&presel);
goto nochange; goto nochange;
@ -5892,16 +5894,16 @@ nochange:
/* If opened as vim plugin and Enter/^M pressed, pick */ /* If opened as vim plugin and Enter/^M pressed, pick */
if (g_state.picker && sel == SEL_GOIN) { if (g_state.picker && sel == SEL_GOIN) {
appendfpath(newpath, mkpath(path, pdents[cur].name, newpath)); appendfpath(newpath, mkpath(path, pent->name, newpath));
writesel(pselbuf, selbufpos - 1); writesel(pselbuf, selbufpos - 1);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (sel == SEL_NAV_IN) { if (sel == SEL_NAV_IN) {
/* If in listing dir, go to target on `l` or Right on symlink */ /* If in listing dir, go to target on `l` or Right on symlink */
if (listpath && S_ISLNK(pdents[cur].mode) if (listpath && S_ISLNK(pent->mode)
&& is_prefix(path, listpath, xstrlen(listpath))) { && is_prefix(path, listpath, xstrlen(listpath))) {
if (!realpath(pdents[cur].name, newpath)) { if (!realpath(pent->name, newpath)) {
printwarn(&presel); printwarn(&presel);
goto nochange; goto nochange;
} }
@ -5919,7 +5921,7 @@ nochange:
cdprep(lastdir, NULL, path, newpath) cdprep(lastdir, NULL, path, newpath)
? (presel = FILTER) : (watch = TRUE); ? (presel = FILTER) : (watch = TRUE);
xstrsncpy(lastname, pdents[cur].name, NAME_MAX + 1); xstrsncpy(lastname, pent->name, NAME_MAX + 1);
goto begin; goto begin;
} }
@ -5939,7 +5941,7 @@ nochange:
rundir[0] = '\0'; rundir[0] = '\0';
if (chdir(path) == -1 if (chdir(path) == -1
|| !run_selected_plugin(&path, pdents[cur].name, || !run_selected_plugin(&path, pent->name,
runfile, &lastname, &lastdir)) { runfile, &lastname, &lastdir)) {
DPRINTF_S("plugin failed!"); DPRINTF_S("plugin failed!");
} }
@ -5971,15 +5973,19 @@ nochange:
continue; continue;
} }
/* Get the extension for regext match */
tmp = xextension(pent->name, pent->nlen - 1);
if (tmp)
++tmp;
#ifdef PCRE #ifdef PCRE
if (!pcre_exec(archive_pcre, NULL, pdents[cur].name, if (tmp && !pcre_exec(archive_pcre, NULL, tmp,
xstrlen(pdents[cur].name), 0, 0, NULL, 0)) { pent->nlen - (tmp - pent->name) - 1, 0, 0, NULL, 0)) {
#else #else
if (!regexec(&archive_re, pdents[cur].name, 0, NULL, 0)) { if (tmp && !regexec(&archive_re, tmp, 0, NULL, 0)) {
#endif #endif
r = get_input(messages[MSG_ARCHIVE_OPTS]); r = get_input(messages[MSG_ARCHIVE_OPTS]);
if (r == 'l' || r == 'x') { if (r == 'l' || r == 'x') {
mkpath(path, pdents[cur].name, newpath); mkpath(path, pent->name, newpath);
handle_archive(newpath, r); handle_archive(newpath, r);
if (r == 'l') { if (r == 'l') {
statusbar(path); statusbar(path);