]> Sergey Matveev's repositories - nnn.git/commitdiff
Simplify and preprocess archive handling
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 14 Aug 2020 02:50:01 +0000 (08:20 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 14 Aug 2020 02:50:01 +0000 (08:20 +0530)
nnn.1
src/nnn.c

diff --git a/nnn.1 b/nnn.1
index 3aa4ab229ffe133194d7d1dd9327138781f017e2..ec8df82407d3af068b254bb7cb1a8ce37f6ffb9e 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -455,9 +455,9 @@ separated by \fI;\fR:
     If xterm 256 colors aren't supported, earlier colorscheme will be used.
 .Ed
 .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
-    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.
 .Ed
index 1f0386ba3893672b23335a10f310e76ee697a6a7..0b8a778509351af29d694d1efec294694ae4f12c 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -663,7 +663,7 @@ static const char * const patterns[] = {
        "sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s",
        "sed 's|^\\([^#/][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' "
                "%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",
 };
 
@@ -5587,6 +5587,7 @@ static bool browse(char *ipath, const char *session, int pkey)
        char rundir[PATH_MAX] __attribute__ ((aligned));
        char runfile[NAME_MAX + 1] __attribute__ ((aligned));
        char *path, *lastdir, *lastname, *dir, *tmp;
+       pEntry pent;
        enum action sel;
        struct stat sb;
        int r = -1, presel, selstartid = 0, selendid = 0;
@@ -5863,11 +5864,12 @@ nochange:
                        if (!ndents)
                                goto begin;
 
-                       mkpath(path, pdents[cur].name, newpath);
+                       pent = &pdents[cur];
+                       mkpath(path, pent->name, newpath);
                        DPRINTF_S(newpath);
 
                        /* Visit directory */
-                       if (pdents[cur].flags & DIR_OR_LINK_TO_DIR) {
+                       if (pent->flags & DIR_OR_LINK_TO_DIR) {
                                if (chdir(newpath) == -1) {
                                        printwarn(&presel);
                                        goto nochange;
@@ -5892,16 +5894,16 @@ nochange:
 
                        /* If opened as vim plugin and Enter/^M pressed, pick */
                        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);
                                return EXIT_SUCCESS;
                        }
 
                        if (sel == SEL_NAV_IN) {
                                /* 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))) {
-                                       if (!realpath(pdents[cur].name, newpath)) {
+                                       if (!realpath(pent->name, newpath)) {
                                                printwarn(&presel);
                                                goto nochange;
                                        }
@@ -5919,7 +5921,7 @@ nochange:
 
                                        cdprep(lastdir, NULL, path, newpath)
                                               ? (presel = FILTER) : (watch = TRUE);
-                                       xstrsncpy(lastname, pdents[cur].name, NAME_MAX + 1);
+                                       xstrsncpy(lastname, pent->name, NAME_MAX + 1);
                                        goto begin;
                                }
 
@@ -5939,7 +5941,7 @@ nochange:
                                        rundir[0] = '\0';
 
                                        if (chdir(path) == -1
-                                           || !run_selected_plugin(&path, pdents[cur].name,
+                                           || !run_selected_plugin(&path, pent->name,
                                                                    runfile, &lastname, &lastdir)) {
                                                DPRINTF_S("plugin failed!");
                                        }
@@ -5971,15 +5973,19 @@ nochange:
                                continue;
                        }
 
+                       /* Get the extension for regext match */
+                       tmp = xextension(pent->name, pent->nlen - 1);
+                       if (tmp)
+                               ++tmp;
 #ifdef PCRE
-                       if (!pcre_exec(archive_pcre, NULL, pdents[cur].name,
-                                      xstrlen(pdents[cur].name), 0, 0, NULL, 0)) {
+                       if (tmp && !pcre_exec(archive_pcre, NULL, tmp,
+                                             pent->nlen - (tmp - pent->name) - 1, 0, 0, NULL, 0)) {
 #else
-                       if (!regexec(&archive_re, pdents[cur].name, 0, NULL, 0)) {
+                       if (tmp && !regexec(&archive_re, tmp, 0, NULL, 0)) {
 #endif
                                r = get_input(messages[MSG_ARCHIVE_OPTS]);
                                if (r == 'l' || r == 'x') {
-                                       mkpath(path, pdents[cur].name, newpath);
+                                       mkpath(path, pent->name, newpath);
                                        handle_archive(newpath, r);
                                        if (r == 'l') {
                                                statusbar(path);