nnn.1 | 1 + src/nnn.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- src/nnn.h | 2 ++ diff --git a/nnn.1 b/nnn.1 index 84b184cb5e89a31ce862d09ec8da1e0778c379ce..eff3f1c46d0a2f6e0ac0de1fe3b8b7f04e6574fe 100644 --- a/nnn.1 +++ b/nnn.1 @@ -213,6 +213,7 @@ - | Go to last visited dir . | Show hidden files ; | Run a plugin by its key = | Launch a GUI application + > | Export file list @ | Visit start dir ] | Show command prompt ` | Visit / diff --git a/src/nnn.c b/src/nnn.c index c47c0c559538947f6e0547c21dd3cb06ef119c89..4bca0e6ec2a2b7e7d2b7f1b6b6627275ad85b374 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -516,8 +516,9 @@ #define MSG_INVALID_REG 36 #define MSG_ORDER 37 #define MSG_LAZY 38 #define MSG_IGNORED 39 +#define MSG_RM_TMP 40 #ifndef DIR_LIMITED_SELECTION -#define MSG_DIR_CHANGED 40 /* Must be the last entry */ +#define MSG_DIR_CHANGED 41 /* Must be the last entry */ #endif static const char * const messages[] = { @@ -561,6 +562,7 @@ "invalid regex", "'a'u / 'd'u / 'e'xtn / 'r'ev / 's'ize / 't'ime / 'v'er / 'c'lear?", "unmount failed! try lazy?", "ignoring invalid paths...", + "remove tmp file?", #ifndef DIR_LIMITED_SELECTION "dir changed, range sel off", /* Must be the last entry */ #endif @@ -1440,6 +1442,39 @@ return TRUE; } +static void export_file_list(void) +{ + int fd, r = 0; + struct entry *pdent = dents; + + if (!ndents) + return; + + fd = create_tmp_file(); + if (fd == -1) { + DPRINTF_S(strerror(errno)); + return; + } + + for (; r < ndents; ++pdent, ++r) { + if (write(fd, pdent->name, pdent->nlen - 1) != (pdent->nlen - 1)) + break; + + if ((r != ndents - 1) && (write(fd, "\n", 1) != 1)) + break; + } + + if (close(fd)) { + DPRINTF_S(strerror(errno)); + } + + spawn(editor, g_tmpfpath, NULL, NULL, F_CLI); + + r = get_input(messages[MSG_RM_TMP]); + if (xconfirm(r)) + unlink(g_tmpfpath); +} + /* Initialize curses mode */ static bool initcurses(void *oldmask) { @@ -2532,6 +2567,7 @@ case '-': // fallthrough /* Visit last visited dir */ case '.': // fallthrough /* Show hidden files */ case ';': // fallthrough /* Run plugin key */ case '=': // fallthrough /* Launch app */ + case '>': // fallthrough /* Export file list */ case '@': // fallthrough /* Visit start dir */ case ']': // fallthorugh /* Prompt key */ case '`': // fallthrough /* Visit / */ @@ -4041,9 +4077,9 @@ "b^R Rename/dup%-14cr Batch rename\n" "cz Archive%-17ce Edit in EDITOR\n" "5Space ^J (Un)select%-11cm ^K Mark range/clear\n" "9p ^P Copy sel here%-11ca Select all\n" - "9v ^V Move sel here%-8cw ^W Copy/move sel as\n" + "9v ^V Move sel here%-8cw ^W cp/mv sel as\n" "9x ^X Delete%-18cE Edit sel\n" - "c* Toggle exe%-0c\n" + "c* Toggle exe%-14c> Export list\n" "1MISC\n" "9; ^S Select plugin%-11c= Launch app\n" "9! ^] Shell%-19c] Cmd prompt\n" @@ -6220,6 +6256,10 @@ if (sel == SEL_QUITCD || getenv("NNN_TMPFILE")) cfg.picker ? selbufpos = 0 : write_lastdir(path); free(mark); return sel == SEL_QUITFAIL ? _FAILURE : _SUCCESS; + case SEL_EXPORT: + export_file_list(); + cfg.filtermode ? presel = FILTER : statusbar(path); + goto nochange; default: if (xlines != LINES || xcols != COLS) setdirwatch(); /* Terminal resized */ diff --git a/src/nnn.h b/src/nnn.h index a832939a007686ef1ae313271380f9584517a775..f0c03b16e06cb571dd7d0946ca6f87cc5ec44045 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -96,6 +96,7 @@ SEL_QUITCTX, SEL_QUITCD, SEL_QUIT, SEL_QUITFAIL, + SEL_EXPORT, #ifndef NOMOUSE SEL_CLICK, #endif @@ -247,6 +248,7 @@ /* Quit */ { CONTROL('Q'), SEL_QUIT }, /* Quit with an error code */ { 'Q', SEL_QUITFAIL }, + { '>', SEL_EXPORT }, #ifndef NOMOUSE { KEY_MOUSE, SEL_CLICK }, #endif