mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 13:51:31 +00:00
Support file cp, mv, rm through selection
This commit is contained in:
parent
721ac62f72
commit
4407f29dd3
|
@ -254,7 +254,7 @@ optional args:
|
||||||
? Help, settings
|
? Help, settings
|
||||||
q Quit context
|
q Quit context
|
||||||
^G Quit and cd
|
^G Quit and cd
|
||||||
Q, ^X Quit
|
Q, ^Q Quit
|
||||||
```
|
```
|
||||||
|
|
||||||
Help & settings, file details, media info and archive listing are shown in the PAGER. Please use the PAGER-specific keys in these screens.
|
Help & settings, file details, media info and archive listing are shown in the PAGER. Please use the PAGER-specific keys in these screens.
|
||||||
|
|
40
src/nnn.c
40
src/nnn.c
|
@ -782,6 +782,7 @@ static void spawn(const char *file, const char *arg1, const char *arg2, const ch
|
||||||
|
|
||||||
if (flag & F_SIGINT)
|
if (flag & F_SIGINT)
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
|
|
||||||
execlp(file, file, arg1, arg2, NULL);
|
execlp(file, file, arg1, arg2, NULL);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2007,7 +2008,7 @@ static int show_help(char *path)
|
||||||
"e? Help, settings\n"
|
"e? Help, settings\n"
|
||||||
"eq Quit context\n"
|
"eq Quit context\n"
|
||||||
"d^G Quit and cd\n"
|
"d^G Quit and cd\n"
|
||||||
"aQ, ^X Quit\n\n"};
|
"aQ, ^Q Quit\n\n"};
|
||||||
|
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2984,6 +2985,7 @@ nochange:
|
||||||
r = mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
r = mkpath(path, dents[cur].name, newpath, PATH_MAX);
|
||||||
if (!appendfpath(newpath, r))
|
if (!appendfpath(newpath, r))
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
|
||||||
++ncp;
|
++ncp;
|
||||||
printmsg(newpath);
|
printmsg(newpath);
|
||||||
} else if (cfg.quote) {
|
} else if (cfg.quote) {
|
||||||
|
@ -3013,6 +3015,7 @@ nochange:
|
||||||
writecp(newpath, r - 1); /* Truncate NULL from end */
|
writecp(newpath, r - 1); /* Truncate NULL from end */
|
||||||
else
|
else
|
||||||
spawn(copier, newpath, NULL, NULL, F_NOTRACE);
|
spawn(copier, newpath, NULL, NULL, F_NOTRACE);
|
||||||
|
|
||||||
printmsg(newpath);
|
printmsg(newpath);
|
||||||
}
|
}
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
@ -3067,6 +3070,41 @@ nochange:
|
||||||
else
|
else
|
||||||
printmsg("multi-copy off");
|
printmsg("multi-copy off");
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
case SEL_CP:
|
||||||
|
case SEL_MV:
|
||||||
|
case SEL_RMMUL:
|
||||||
|
{
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
if (!g_cppath[0]) {
|
||||||
|
printmsg("copy file not found");
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sel == SEL_CP)
|
||||||
|
r = asprintf(&cmd, "xargs -0 -d \'\n\' -a %s cp -ir --preserve=all -t .", g_cppath);
|
||||||
|
else if (sel == SEL_MV)
|
||||||
|
r = asprintf(&cmd, "xargs -0 -d \'\n\' -a %s mv -i -t .", g_cppath);
|
||||||
|
else /* SEL_RMMUL */
|
||||||
|
r = asprintf(&cmd, "xargs -0 -d \'\n\' -a %s rm -Ir", g_cppath);
|
||||||
|
|
||||||
|
if (r == -1) {
|
||||||
|
printwarn();
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
spawn("sh", "-c", cmd, path, F_NORMAL | F_SIGINT);
|
||||||
|
free(cmd);
|
||||||
|
|
||||||
|
copycurname();
|
||||||
|
if (cfg.filtermode)
|
||||||
|
presel = FILTER;
|
||||||
|
goto begin;
|
||||||
|
}
|
||||||
|
case SEL_RM:
|
||||||
|
lastname[0] = '\0';
|
||||||
|
if (cfg.filtermode)
|
||||||
|
presel = FILTER;
|
||||||
|
goto begin;
|
||||||
case SEL_QUOTE:
|
case SEL_QUOTE:
|
||||||
cfg.quote ^= 1;
|
cfg.quote ^= 1;
|
||||||
DPRINTF_D(cfg.quote);
|
DPRINTF_D(cfg.quote);
|
||||||
|
|
16
src/nnn.h
16
src/nnn.h
|
@ -69,6 +69,10 @@ enum action {
|
||||||
SEL_COPY,
|
SEL_COPY,
|
||||||
SEL_COPYMUL,
|
SEL_COPYMUL,
|
||||||
SEL_COPYLIST,
|
SEL_COPYLIST,
|
||||||
|
SEL_CP,
|
||||||
|
SEL_MV,
|
||||||
|
SEL_RMMUL,
|
||||||
|
SEL_RM,
|
||||||
SEL_QUOTE,
|
SEL_QUOTE,
|
||||||
SEL_OPEN,
|
SEL_OPEN,
|
||||||
SEL_NEW,
|
SEL_NEW,
|
||||||
|
@ -192,6 +196,14 @@ static struct key bindings[] = {
|
||||||
{ CONTROL('Y'), SEL_COPYMUL, "", "" },
|
{ CONTROL('Y'), SEL_COPYMUL, "", "" },
|
||||||
/* Show list of copied files */
|
/* Show list of copied files */
|
||||||
{ 'y', SEL_COPYLIST, "", "" },
|
{ 'y', SEL_COPYLIST, "", "" },
|
||||||
|
/* Copy from copy buffer */
|
||||||
|
{ 'P', SEL_CP, "", "" },
|
||||||
|
/* Move from copy buffer */
|
||||||
|
{ 'V', SEL_MV, "", "" },
|
||||||
|
/* Delete from copy buffer */
|
||||||
|
{ CONTROL('X'), SEL_RMMUL, "", "" },
|
||||||
|
/* Delete currently selected */
|
||||||
|
{ 'X', SEL_RM, "", "" },
|
||||||
/* Toggle quote on while copy */
|
/* Toggle quote on while copy */
|
||||||
{ CONTROL('T'), SEL_QUOTE, "", "" },
|
{ CONTROL('T'), SEL_QUOTE, "", "" },
|
||||||
/* Open in a custom application */
|
/* Open in a custom application */
|
||||||
|
@ -220,6 +232,6 @@ static struct key bindings[] = {
|
||||||
/* Change dir on quit */
|
/* Change dir on quit */
|
||||||
{ CONTROL('G'), SEL_CDQUIT, "", "" },
|
{ CONTROL('G'), SEL_CDQUIT, "", "" },
|
||||||
/* Quit */
|
/* Quit */
|
||||||
{ 'Q', SEL_QUIT, "", "" },
|
{ 'Q', SEL_QUIT, "", "" },
|
||||||
{ CONTROL('X'), SEL_QUIT, "", "" },
|
{ CONTROL('Q'), SEL_QUIT, "", "" },
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue