From b1027150ed09ddeb9acab56a29e216c7196be4e1 Mon Sep 17 00:00:00 2001 From: lvgx Date: Sat, 23 May 2020 14:03:37 +0200 Subject: Add -a option to generate a temporary NNN_FIFO (#588) * Add -a option to generate a temporary NNN_FIFO * Add documentation for -a option * plugins/README.md: promote the use of -a This obsoletes the global FIFO unlink trick, so I remove mentions of it. @jarun update: Polish -a --- src/nnn.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nnn.c b/src/nnn.c index 89c4a48..b45eeb2 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -400,6 +400,7 @@ static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned)); #define STATE_FORTUNE 0x20 #define STATE_TRASH 0x40 #define STATE_FORCEQUIT 0x80 +#define STATE_AUTOFIFO 0x100 static uint g_states; @@ -6726,6 +6727,9 @@ static void usage(void) "positional args:\n" " PATH start dir [default: .]\n\n" "optional args:\n" +#ifndef NOFIFO + " -a auto NNN_FIFO\n" +#endif " -A no dir auto-select\n" " -b key open bookmark key (trumps -s/S)\n" " -c cli-only NNN_OPENER (trumps -e)\n" @@ -6880,6 +6884,11 @@ static void cleanup(void) free(ihashbmp); free(bookmark); free(plug); +#ifndef NOFIFO + if (g_states & STATE_AUTOFIFO) + unlink(fifopath); +#endif + #ifdef DBGMODE disabledbg(); #endif @@ -6906,8 +6915,13 @@ int main(int argc, char *argv[]) while ((opt = (env_opts_id > 0 ? env_opts[--env_opts_id] - : getopt(argc, argv, "Ab:cdeEfFgHKl:nop:P:QrRs:St:T:Vxh"))) != -1) { + : getopt(argc, argv, "aAb:cdeEfFgHKl:nop:P:QrRs:St:T:Vxh"))) != -1) { switch (opt) { +#ifndef NOFIFO + case 'a': + g_states |= STATE_AUTOFIFO; + break; +#endif case 'A': cfg.autoselect = 0; break; @@ -7154,6 +7168,12 @@ int main(int argc, char *argv[]) #ifndef NOFIFO /* Create fifo */ + if (g_states & STATE_AUTOFIFO) { + g_tmpfpath[tmpfplen - 1] = '\0'; + snprintf(g_buf, CMD_LEN_MAX, "%s/nnn-fifo.%d", g_tmpfpath, getpid()); + setenv("NNN_FIFO", g_buf, TRUE); + } + fifopath = xgetenv("NNN_FIFO", NULL); if (fifopath) { if (mkfifo(fifopath, 0600) != 0 && !(errno == EEXIST && access(fifopath, W_OK) == 0)) { -- cgit v1.2.3-70-g09d2