mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Shared previewer and explorer
This commit is contained in:
parent
9f86015c16
commit
4f297fa147
11
nnn.1
11
nnn.1
|
@ -6,8 +6,10 @@
|
||||||
.Nd The unorthodox terminal file manager.
|
.Nd The unorthodox terminal file manager.
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Ar -aAcCdDeEfgHJKlnQrRSuUVwxXh
|
.Op Ar -aAcCdDeEfgHJKnQrRSuUVwxh
|
||||||
.Op Ar -b key
|
.Op Ar -b key
|
||||||
|
.Op Ar -F val
|
||||||
|
.Op Ar -l val
|
||||||
.Op Ar -p file
|
.Op Ar -p file
|
||||||
.Op Ar -P key
|
.Op Ar -P key
|
||||||
.Op Ar -s name
|
.Op Ar -s name
|
||||||
|
@ -72,6 +74,10 @@ supports the following options:
|
||||||
.Fl f
|
.Fl f
|
||||||
use readline history file
|
use readline history file
|
||||||
.Pp
|
.Pp
|
||||||
|
.Fl "F val"
|
||||||
|
fifo notification mode
|
||||||
|
0: notify as previewer, 1: notify as explorer, 2: both
|
||||||
|
.Pp
|
||||||
.Fl g
|
.Fl g
|
||||||
use regex filters instead of substring match
|
use regex filters instead of substring match
|
||||||
.Pp
|
.Pp
|
||||||
|
@ -139,9 +145,6 @@ supports the following options:
|
||||||
copy path to system clipboard on select
|
copy path to system clipboard on select
|
||||||
show xterm title (if non-picker mode)
|
show xterm title (if non-picker mode)
|
||||||
.Pp
|
.Pp
|
||||||
.Fl "X fifo"
|
|
||||||
run in explorer mode, where file path is sent to 'fifo' on 'Enter' or '^M'
|
|
||||||
.Pp
|
|
||||||
.Fl h
|
.Fl h
|
||||||
show program help and exit
|
show program help and exit
|
||||||
.Sh CONFIGURATION
|
.Sh CONFIGURATION
|
||||||
|
|
95
src/nnn.c
95
src/nnn.c
|
@ -331,7 +331,6 @@ typedef struct {
|
||||||
uint_t dircolor : 1; /* Current status of dir color */
|
uint_t dircolor : 1; /* Current status of dir color */
|
||||||
uint_t picker : 1; /* Write selection to user-specified file */
|
uint_t picker : 1; /* Write selection to user-specified file */
|
||||||
uint_t picked : 1; /* Plugin has picked files */
|
uint_t picked : 1; /* Plugin has picked files */
|
||||||
uint_t explorer : 1; /* Explorer mode: send picked files to FIFO without exiting */
|
|
||||||
uint_t runplugin : 1; /* Choose plugin mode */
|
uint_t runplugin : 1; /* Choose plugin mode */
|
||||||
uint_t runctx : 3; /* The context in which plugin is to be run */
|
uint_t runctx : 3; /* The context in which plugin is to be run */
|
||||||
uint_t selmode : 1; /* Set when selecting files */
|
uint_t selmode : 1; /* Set when selecting files */
|
||||||
|
@ -341,7 +340,8 @@ typedef struct {
|
||||||
uint_t uidgid : 1; /* Show owner and group info */
|
uint_t uidgid : 1; /* Show owner and group info */
|
||||||
uint_t prstssn : 1; /* Persistent session */
|
uint_t prstssn : 1; /* Persistent session */
|
||||||
uint_t duinit : 1; /* Initialize disk usage */
|
uint_t duinit : 1; /* Initialize disk usage */
|
||||||
uint_t reserved : 7; /* Adjust when adding/removing a field */
|
uint_t fifobits : 2; /* b00: notify previewer, b01: notify explorer, b10: notify both */
|
||||||
|
uint_t reserved : 6; /* Adjust when adding/removing a field */
|
||||||
} runstate;
|
} runstate;
|
||||||
|
|
||||||
/* Contexts or workspaces */
|
/* Contexts or workspaces */
|
||||||
|
@ -402,8 +402,7 @@ static context g_ctx[CTX_MAX] __attribute__ ((aligned));
|
||||||
static int ndents, cur, last, curscroll, last_curscroll, total_dents = ENTRY_INCR, scroll_lines = 1;
|
static int ndents, cur, last, curscroll, last_curscroll, total_dents = ENTRY_INCR, scroll_lines = 1;
|
||||||
static int nselected;
|
static int nselected;
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
static int hfifofd = -1; /* FIFO used in hover (NNN_FIFO) */
|
static int fifofd = -1;
|
||||||
static int efifofd = -1; /* FIFO used in explorer mode (-X) */
|
|
||||||
#endif
|
#endif
|
||||||
static uint_t idletimeout, selbufpos, lastappendpos, selbuflen;
|
static uint_t idletimeout, selbufpos, lastappendpos, selbuflen;
|
||||||
static ushort_t xlines, xcols;
|
static ushort_t xlines, xcols;
|
||||||
|
@ -426,8 +425,7 @@ static char *plgpath;
|
||||||
static char *pnamebuf, *pselbuf;
|
static char *pnamebuf, *pselbuf;
|
||||||
static char *mark;
|
static char *mark;
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
static char *hfifopath; /* FIFO used in hover (NNN_FIFO) */
|
static char *fifopath;
|
||||||
static char *efifopath; /* FIFO used in explorer mode (-X) */
|
|
||||||
#endif
|
#endif
|
||||||
static ullong_t *ihashbmp;
|
static ullong_t *ihashbmp;
|
||||||
static struct entry *pdents;
|
static struct entry *pdents;
|
||||||
|
@ -813,7 +811,7 @@ static void move_cursor(int target, int ignore_scrolloff);
|
||||||
static char *load_input(int fd, const char *path);
|
static char *load_input(int fd, const char *path);
|
||||||
static int set_sort_flags(int r);
|
static int set_sort_flags(int r);
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
static void notify_fifo(bool force, bool explorer);
|
static void notify_fifo(bool force);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
|
@ -2760,8 +2758,8 @@ try_quit:
|
||||||
c = CONTROL('Q');
|
c = CONTROL('Q');
|
||||||
} else {
|
} else {
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
/* Send hovered path to NNN_FIFO */
|
if (!(g_state.fifobits & 1))
|
||||||
notify_fifo(TRUE, FALSE);
|
notify_fifo(TRUE); /* Send hovered path to NNN_FIFO */
|
||||||
#endif
|
#endif
|
||||||
escaped = TRUE;
|
escaped = TRUE;
|
||||||
settimeout();
|
settimeout();
|
||||||
|
@ -5414,22 +5412,18 @@ static void populate(char *path, char *lastname)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
static void notify_fifo(bool force, bool explorer)
|
static void notify_fifo(bool force)
|
||||||
{
|
{
|
||||||
/* refer to the explorer fifo instead of the hover fifo if explorer is true */
|
if (!fifopath)
|
||||||
char **ppath = explorer ? &efifopath : &hfifopath;
|
|
||||||
int *pptr = explorer ? &efifofd : &hfifofd;
|
|
||||||
|
|
||||||
if (!(*ppath))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (*pptr == -1) {
|
if (fifofd == -1) {
|
||||||
*pptr = open(*ppath, O_WRONLY|O_NONBLOCK|O_CLOEXEC);
|
fifofd = open(fifopath, O_WRONLY|O_NONBLOCK|O_CLOEXEC);
|
||||||
if (*pptr == -1) {
|
if (fifofd == -1) {
|
||||||
if (errno != ENXIO)
|
if (errno != ENXIO)
|
||||||
/* Unexpected error, the FIFO file might have been removed */
|
/* Unexpected error, the FIFO file might have been removed */
|
||||||
/* We give up FIFO notification */
|
/* We give up FIFO notification */
|
||||||
*ppath = NULL;
|
fifopath = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5446,7 +5440,7 @@ static void notify_fifo(bool force, bool explorer)
|
||||||
|
|
||||||
path[len - 1] = '\n';
|
path[len - 1] = '\n';
|
||||||
|
|
||||||
ssize_t ret = write(*pptr, path, len);
|
ssize_t ret = write(fifofd, path, len);
|
||||||
|
|
||||||
if (ret != (ssize_t)len && !(ret == -1 && (errno == EAGAIN || errno == EPIPE))) {
|
if (ret != (ssize_t)len && !(ret == -1 && (errno == EAGAIN || errno == EPIPE))) {
|
||||||
DPRINTF_S(strerror(errno));
|
DPRINTF_S(strerror(errno));
|
||||||
|
@ -5482,7 +5476,8 @@ static void move_cursor(int target, int ignore_scrolloff)
|
||||||
curscroll = MAX(curscroll, MAX(cur - (onscreen - 1), 0));
|
curscroll = MAX(curscroll, MAX(cur - (onscreen - 1), 0));
|
||||||
|
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
notify_fifo(FALSE, FALSE);
|
if (!(g_state.fifobits & 1))
|
||||||
|
notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6347,8 +6342,9 @@ nochange:
|
||||||
if (r != cur)
|
if (r != cur)
|
||||||
move_cursor(r, 1);
|
move_cursor(r, 1);
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
else if (event.bstate == BUTTON1_PRESSED)
|
else if ((event.bstate == BUTTON1_PRESSED) && !(g_state.fifobits & 1)) {
|
||||||
notify_fifo(TRUE, FALSE);
|
notify_fifo(TRUE); /* Send clicked path to NNN_FIFO */
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Handle right click selection */
|
/* Handle right click selection */
|
||||||
if (event.bstate == BUTTON3_PRESSED) {
|
if (event.bstate == BUTTON3_PRESSED) {
|
||||||
|
@ -6420,8 +6416,8 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
if (g_state.explorer && sel == SEL_OPEN) {
|
if (g_state.fifobits && sel == SEL_OPEN) {
|
||||||
notify_fifo(TRUE, TRUE);
|
notify_fifo(TRUE); /* Send opened path to NNN_FIFO */
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -7630,6 +7626,9 @@ static void usage(void)
|
||||||
" -E internal edits in EDITOR\n"
|
" -E internal edits in EDITOR\n"
|
||||||
#ifndef NORL
|
#ifndef NORL
|
||||||
" -f use readline history file\n"
|
" -f use readline history file\n"
|
||||||
|
#endif
|
||||||
|
#ifndef NOFIFO
|
||||||
|
" -F val fifo mode [0:preview 1:explore 2:both]\n"
|
||||||
#endif
|
#endif
|
||||||
" -g regex filters\n"
|
" -g regex filters\n"
|
||||||
" -H show hidden files\n"
|
" -H show hidden files\n"
|
||||||
|
@ -7638,7 +7637,7 @@ static void usage(void)
|
||||||
" -l val set scroll lines\n"
|
" -l val set scroll lines\n"
|
||||||
" -n type-to-nav mode\n"
|
" -n type-to-nav mode\n"
|
||||||
" -o open files only on Enter\n"
|
" -o open files only on Enter\n"
|
||||||
" -p file selection file [stdout if '-']\n"
|
" -p file selection file [-:stdout]\n"
|
||||||
" -P key run plugin key\n"
|
" -P key run plugin key\n"
|
||||||
" -Q no quit confirmation\n"
|
" -Q no quit confirmation\n"
|
||||||
" -r use advcpmv patched cp, mv\n"
|
" -r use advcpmv patched cp, mv\n"
|
||||||
|
@ -7657,9 +7656,6 @@ static void usage(void)
|
||||||
" -w place HW cursor on hovered\n"
|
" -w place HW cursor on hovered\n"
|
||||||
#ifndef NOX11
|
#ifndef NOX11
|
||||||
" -x notis, selection sync, xterm title\n"
|
" -x notis, selection sync, xterm title\n"
|
||||||
#endif
|
|
||||||
#ifndef NOFIFO
|
|
||||||
" -X fifo explorer mode\n"
|
|
||||||
#endif
|
#endif
|
||||||
" -h show help\n\n"
|
" -h show help\n\n"
|
||||||
"v%s\n%s\n", __func__, VERSION, GENERAL_INFO);
|
"v%s\n%s\n", __func__, VERSION, GENERAL_INFO);
|
||||||
|
@ -7785,9 +7781,7 @@ static void cleanup(void)
|
||||||
free(plug);
|
free(plug);
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
if (g_state.autofifo)
|
if (g_state.autofifo)
|
||||||
unlink(hfifopath);
|
unlink(fifopath);
|
||||||
if (g_state.explorer)
|
|
||||||
unlink(efifopath);
|
|
||||||
#endif
|
#endif
|
||||||
if (g_state.pluginit)
|
if (g_state.pluginit)
|
||||||
unlink(g_pipepath);
|
unlink(g_pipepath);
|
||||||
|
@ -7819,7 +7813,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
while ((opt = (env_opts_id > 0
|
while ((opt = (env_opts_id > 0
|
||||||
? env_opts[--env_opts_id]
|
? env_opts[--env_opts_id]
|
||||||
: getopt(argc, argv, "aAb:cCdDeEfgHJKl:nop:P:QrRs:St:T:uUVwxX:h"))) != -1) {
|
: getopt(argc, argv, "aAb:cCdDeEfF:gHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
case 'a':
|
case 'a':
|
||||||
|
@ -7856,6 +7850,12 @@ int main(int argc, char *argv[])
|
||||||
rlhist = TRUE;
|
rlhist = TRUE;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
#ifndef NOFIFO
|
||||||
|
case 'F':
|
||||||
|
if (env_opts_id < 0)
|
||||||
|
g_state.fifobits = atoi(optarg);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case 'g':
|
case 'g':
|
||||||
cfg.regex = 1;
|
cfg.regex = 1;
|
||||||
filterfn = &visible_re;
|
filterfn = &visible_re;
|
||||||
|
@ -7946,12 +7946,6 @@ int main(int argc, char *argv[])
|
||||||
case 'x':
|
case 'x':
|
||||||
cfg.x11 = 1;
|
cfg.x11 = 1;
|
||||||
break;
|
break;
|
||||||
case 'X':
|
|
||||||
#ifndef NOFIFO
|
|
||||||
g_state.explorer = TRUE;
|
|
||||||
efifopath = optarg;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -8107,18 +8101,9 @@ int main(int argc, char *argv[])
|
||||||
setenv("NNN_FIFO", g_buf, TRUE);
|
setenv("NNN_FIFO", g_buf, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
hfifopath = xgetenv("NNN_FIFO", NULL);
|
fifopath = xgetenv("NNN_FIFO", NULL);
|
||||||
if (hfifopath) {
|
if (fifopath) {
|
||||||
if (mkfifo(hfifopath, 0600) != 0 && !(errno == EEXIST && access(hfifopath, W_OK) == 0)) {
|
if (mkfifo(fifopath, 0600) != 0 && !(errno == EEXIST && access(fifopath, W_OK) == 0)) {
|
||||||
xerror();
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
sigaction(SIGPIPE, &(struct sigaction){.sa_handler = SIG_IGN}, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_state.explorer) {
|
|
||||||
if (mkfifo(efifopath, 0600) != 0 && !(errno == EEXIST && access(efifopath, W_OK) == 0)) {
|
|
||||||
xerror();
|
xerror();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -8273,11 +8258,9 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
notify_fifo(FALSE, FALSE);
|
notify_fifo(FALSE);
|
||||||
if (hfifofd != -1)
|
if (fifofd != -1)
|
||||||
close(hfifofd);
|
close(fifofd);
|
||||||
if (efifofd != -1)
|
|
||||||
close(efifofd);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return opt;
|
return opt;
|
||||||
|
|
Loading…
Reference in a new issue