]> Sergey Matveev's repositories - nnn.git/commitdiff
Support archive creation
authorArun Prakash Jana <engineerarun@gmail.com>
Tue, 24 Apr 2018 23:34:37 +0000 (05:04 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 25 Apr 2018 00:10:07 +0000 (05:40 +0530)
README.md
nnn.1
nnn.c
nnn.h

index 22e28bc413e86512c1f7de22e854325a0bd09ea8..55e910dbdc1d8367dec32fde60e4ee8c6b14621e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -90,7 +90,7 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To
   - Desktop search (gnome-search-tool, catfish) integration
 - Mimes
   - Open with desktop opener (default) or specify a custom app
-  - List and extract archives (needs atool)
+  - Create, list and extract archives (needs atool)
   - Optionally open text files in EDITOR (fallback vi)
   - Customizable bash script [nlay](https://github.com/jarun/nnn/wiki/all-about-nlay) to handle actions
 - Information
@@ -237,6 +237,7 @@ optional arguments:
               e | Edit entry in EDITOR
               o | Open DE filemanager
               p | Open entry in PAGER
+              f | Archive entry
               F | List archive
              ^F | Extract archive
              ^K | Copy file path
@@ -291,7 +292,7 @@ The following abbreviations are used in the detail view:
 | xdg-open (Linux), open(1) (OS X) | desktop opener |
 | mediainfo, exiftool | multimedia file details |
 | gnome-search-tool, catfish | desktop search utility |
-| atool | list and extract archives |
+| atool | create, list and extract archives |
 | vidir from moreutils | batch rename, move, delete dir entries |
 | vlock (Linux) | terminal locker |
 | $EDITOR ($VISUAL, if defined) | edit files (fallback vi) |
diff --git a/nnn.1 b/nnn.1
index 4e303154334d114b02a53e112dfa3d2b784ab344..cb69dbb5be58c549334d306c335d30800b8cca38 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -100,6 +100,8 @@ Open current entry in EDITOR (fallback vi)
 Open directory in NNN_DE_FILE_MANAGER
 .It Ic p
 Open current entry in PAGER (fallback less)
+.It Ic f
+Archive current entry
 .It Ic F
 List files in archive
 .It Ic ^F
diff --git a/nnn.c b/nnn.c
index 5c8caf7be89324019737b2d64c947c4c0482f715..35df7b0eacfa49a422377df03683b60b502871f5 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -273,7 +273,8 @@ static struct timespec gtimeout;
 #define OPENER 2
 #define NLAY 3
 #define ATOOL 4
-#define VIDIR 5
+#define APACK 5
+#define VIDIR 6
 
 /* Utilities to open files, run actions */
 static char * const utils[] = {
@@ -286,6 +287,7 @@ static char * const utils[] = {
 #endif
        "nlay",
        "atool",
+       "apack",
        "vidir"
 };
 
@@ -1966,6 +1968,7 @@ show_help(char *path)
             "ee | Edit entry in EDITOR\n"
             "eo | Open DE filemanager\n"
             "ep | Open entry in PAGER\n"
+            "ef | Archive entry\n"
             "eF | List archive\n"
            "d^F | Extract archive\n"
            "d^K | Copy file path\n"
@@ -3068,8 +3071,9 @@ nochange:
                        goto nochange;
                case SEL_OPEN:
                        printprompt("open with: "); // fallthrough
+               case SEL_ARCHIVE: // fallthrough
                case SEL_NEW:
-                       if (sel == SEL_NEW)
+                       if (sel != SEL_OPEN)
                                printprompt("name: ");
 
                        tmp = xreadline(NULL);
@@ -3095,7 +3099,15 @@ nochange:
 
                                mkpath(path, dents[cur].name, newpath, PATH_MAX);
                                spawn(tmp, newpath, NULL, path, r);
+                               continue;
+                       } else if (sel == SEL_ARCHIVE) {
+                               /* newpath is used as temporary buffer */
+                               if (!get_output(newpath, PATH_MAX, "which", utils[APACK], NULL, 0)) {
+                                       printmsg("apack missing");
+                                       continue;
+                               }
 
+                               spawn(utils[APACK], tmp, dents[cur].name, path, F_NORMAL);
                                continue;
                        }
 
diff --git a/nnn.h b/nnn.h
index fa92523325b73a91b83f2f574b0ccc95a77492de..f021567c828965e839335eadfcd90fe9006dffc1 100644 (file)
--- a/nnn.h
+++ b/nnn.h
@@ -27,6 +27,7 @@ enum action {
        SEL_MEDIA,
        SEL_FMEDIA,
        SEL_DFB,
+       SEL_ARCHIVE,
        SEL_LIST,
        SEL_EXTRACT,
        SEL_FSIZE,
@@ -137,6 +138,8 @@ static struct key bindings[] = {
        { 'M',            SEL_FMEDIA,    "-f",   "" },
        /* Open dir in desktop file manager */
        { 'o',            SEL_DFB,       "",     "" },
+       /* Create archive */
+       { 'f',            SEL_ARCHIVE,   "",     "" },
        /* List archive */
        { 'F',            SEL_LIST,      "-l",   "" },
        /* Extract archive */