Przeglądaj źródła

Support extract, list archives with default utils

master
Arun Prakash Jana 5 lat temu
rodzic
commit
de931db8a0
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: A75979F35C080412
1 zmienionych plików z 29 dodań i 19 usunięć
  1. +29
    -19
      src/nnn.c

+ 29
- 19
src/nnn.c Wyświetl plik

@@ -337,10 +337,12 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
#define OPENER 2 #define OPENER 2
#define ATOOL 3 #define ATOOL 3
#define BSDTAR 4 #define BSDTAR 4
#define LOCKER 5
#define CMATRIX 6
#define NLAUNCH 7
#define UNKNOWN 8
#define UNZIP 5
#define TAR 6
#define LOCKER 7
#define CMATRIX 8
#define NLAUNCH 9
#define UNKNOWN 10


/* Utilities to open files, run actions */ /* Utilities to open files, run actions */
static char * const utils[] = { static char * const utils[] = {
@@ -355,6 +357,8 @@ static char * const utils[] = {
#endif #endif
"atool", "atool",
"bsdtar", "bsdtar",
"unzip",
"tar",
#ifdef __APPLE__ #ifdef __APPLE__
"bashlock", "bashlock",
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
@@ -2589,31 +2593,37 @@ static bool show_mediainfo(const char *fpath, const char *arg)
return TRUE; return TRUE;
} }


/* Extracts or lists archive */
static bool handle_archive(char *fpath, const char *dir, char op)
/* List or extract archive */
static void handle_archive(char *fpath, const char *dir, char op)
{ {
char larg[] = "-tf";
char xarg[] = "-xf";
char arg[] = "-tvf"; /* options for tar/bsdtar to list files */
char *util; char *util;


if (getutil(utils[ATOOL])) { if (getutil(utils[ATOOL])) {
util = utils[ATOOL]; util = utils[ATOOL];
larg[1] = op;
larg[2] = xarg[2] = '\0';
} else if (getutil(utils[BSDTAR]))
arg[1] = op;
arg[2] = '\0';
} else if (getutil(utils[BSDTAR])) {
util = utils[BSDTAR]; util = utils[BSDTAR];
else
return FALSE;
if (op == 'x')
arg[1] = op;
} else if (is_suffix(fpath, ".zip")) {
util = utils[UNZIP];
arg[1] = (op == 'l') ? 'v' /* verbose listing */ : '\0';
arg[2] = '\0';
} else {
util = utils[TAR];
if (op == 'x')
arg[1] = op;
}


if (op == 'x') { /* extract */ if (op == 'x') { /* extract */
spawn(util, xarg, fpath, dir, F_NORMAL);
spawn(util, arg, fpath, dir, F_NORMAL);
} else { /* list */ } else { /* list */
exitcurses(); exitcurses();
get_output(NULL, 0, util, larg, fpath, TRUE);
get_output(NULL, 0, util, arg, fpath, TRUE);
refresh(); refresh();
} }

return TRUE;
} }


static char *visit_parent(char *path, char *newpath, int *presel) static char *visit_parent(char *path, char *newpath, int *presel)
@@ -3885,10 +3895,10 @@ nochange:
setdirwatch(); setdirwatch();
goto nochange; goto nochange;
case SEL_ARCHIVELS: case SEL_ARCHIVELS:
r = handle_archive(newpath, path, 'l');
handle_archive(newpath, path, 'l');
break; break;
case SEL_EXTRACT: case SEL_EXTRACT:
r = handle_archive(newpath, path, 'x');
handle_archive(newpath, path, 'x');
break; break;
case SEL_REDRAW: case SEL_REDRAW:
if (ndents) if (ndents)


Ładowanie…
Anuluj
Zapisz