mirror of
https://github.com/jarun/nnn.git
synced 2024-09-11 04:55:25 +03:00
Add option to rm -rf
irrespective of trash setting
This commit is contained in:
parent
94aeaccdbd
commit
eb3888cb09
@ -1,12 +1,8 @@
|
|||||||
# Description: Change key bindings for comfortable use with Colemak keyboard
|
|
||||||
# layout. This diff was made in 4.7 release version of nnn.
|
|
||||||
#
|
|
||||||
# Author: github.com/jacmoe
|
|
||||||
diff --git a/src/nnn.c b/src/nnn.c
|
diff --git a/src/nnn.c b/src/nnn.c
|
||||||
index 21a7370b..2ddb4053 100644
|
index 6792d503..0a59e8e3 100644
|
||||||
--- a/src/nnn.c
|
--- a/src/nnn.c
|
||||||
+++ b/src/nnn.c
|
+++ b/src/nnn.c
|
||||||
@@ -5109,12 +5109,12 @@ static void show_help(const char *path)
|
@@ -5148,12 +5148,12 @@ static void show_help(const char *path)
|
||||||
"2(___n))\n"
|
"2(___n))\n"
|
||||||
"0\n"
|
"0\n"
|
||||||
"1NAVIGATION\n"
|
"1NAVIGATION\n"
|
||||||
@ -24,7 +20,7 @@ index 21a7370b..2ddb4053 100644
|
|||||||
"8B (,) Book(mark)%11b ^/ Select bookmark\n"
|
"8B (,) Book(mark)%11b ^/ Select bookmark\n"
|
||||||
"a1-4 Context%11(Sh)Tab Cycle/new context\n"
|
"a1-4 Context%11(Sh)Tab Cycle/new context\n"
|
||||||
"62Esc ^Q Quit%19^y Next young\n"
|
"62Esc ^Q Quit%19^y Next young\n"
|
||||||
@@ -5122,20 +5122,20 @@ static void show_help(const char *path)
|
@@ -5161,20 +5161,20 @@ static void show_help(const char *path)
|
||||||
"cq Quit context\n"
|
"cq Quit context\n"
|
||||||
"0\n"
|
"0\n"
|
||||||
"1FILTER & PROMPT\n"
|
"1FILTER & PROMPT\n"
|
||||||
@ -46,14 +42,14 @@ index 21a7370b..2ddb4053 100644
|
|||||||
"9p ^P Copy here%12w ^W Cp/mv sel as\n"
|
"9p ^P Copy here%12w ^W Cp/mv sel as\n"
|
||||||
- "9v ^V Move here%15E Edit sel list\n"
|
- "9v ^V Move here%15E Edit sel list\n"
|
||||||
+ "9v ^V Move here%15l Edit sel list\n"
|
+ "9v ^V Move here%15l Edit sel list\n"
|
||||||
"9x ^X Delete%18S Listed sel size\n"
|
"9x ^X Delete or trash%09S Listed sel size\n"
|
||||||
"aEsc Send to FIFO\n"
|
"cX Delete (rm -rf)%07Esc Send to FIFO\n"
|
||||||
"0\n"
|
"0\n"
|
||||||
diff --git a/src/nnn.h b/src/nnn.h
|
diff --git a/src/nnn.h b/src/nnn.h
|
||||||
index 3e4ea19c..b0eb7cdb 100644
|
index bd500244..b12df5c0 100644
|
||||||
--- a/src/nnn.h
|
--- a/src/nnn.h
|
||||||
+++ b/src/nnn.h
|
+++ b/src/nnn.h
|
||||||
@@ -137,12 +137,12 @@ static struct key bindings[] = {
|
@@ -139,12 +139,12 @@ static struct key bindings[] = {
|
||||||
{ '\r', SEL_OPEN },
|
{ '\r', SEL_OPEN },
|
||||||
/* Pure navigate inside */
|
/* Pure navigate inside */
|
||||||
{ KEY_RIGHT, SEL_NAV_IN },
|
{ KEY_RIGHT, SEL_NAV_IN },
|
||||||
@ -69,7 +65,7 @@ index 3e4ea19c..b0eb7cdb 100644
|
|||||||
{ KEY_UP, SEL_PREV },
|
{ KEY_UP, SEL_PREV },
|
||||||
/* Page down */
|
/* Page down */
|
||||||
{ KEY_NPAGE, SEL_PGDN },
|
{ KEY_NPAGE, SEL_PGDN },
|
||||||
@@ -155,11 +155,11 @@ static struct key bindings[] = {
|
@@ -157,11 +157,11 @@ static struct key bindings[] = {
|
||||||
/* First entry */
|
/* First entry */
|
||||||
{ KEY_HOME, SEL_HOME },
|
{ KEY_HOME, SEL_HOME },
|
||||||
{ 'g', SEL_HOME },
|
{ 'g', SEL_HOME },
|
||||||
@ -83,7 +79,7 @@ index 3e4ea19c..b0eb7cdb 100644
|
|||||||
/* Go to first file */
|
/* Go to first file */
|
||||||
{ '\'', SEL_FIRST },
|
{ '\'', SEL_FIRST },
|
||||||
/* Jump to an entry number/offset */
|
/* Jump to an entry number/offset */
|
||||||
@@ -199,7 +199,7 @@ static struct key bindings[] = {
|
@@ -202,7 +202,7 @@ static struct key bindings[] = {
|
||||||
/* Filter */
|
/* Filter */
|
||||||
{ '/', SEL_FLTR },
|
{ '/', SEL_FLTR },
|
||||||
/* Toggle filter mode */
|
/* Toggle filter mode */
|
||||||
@ -92,7 +88,7 @@ index 3e4ea19c..b0eb7cdb 100644
|
|||||||
/* Toggle hide .dot files */
|
/* Toggle hide .dot files */
|
||||||
{ '.', SEL_HIDDEN },
|
{ '.', SEL_HIDDEN },
|
||||||
/* Detailed listing */
|
/* Detailed listing */
|
||||||
@@ -226,7 +226,7 @@ static struct key bindings[] = {
|
@@ -229,7 +229,7 @@ static struct key bindings[] = {
|
||||||
/* Invert selection in current dir */
|
/* Invert selection in current dir */
|
||||||
{ 'A', SEL_SELINV },
|
{ 'A', SEL_SELINV },
|
||||||
/* List, edit selection */
|
/* List, edit selection */
|
||||||
@ -101,7 +97,7 @@ index 3e4ea19c..b0eb7cdb 100644
|
|||||||
/* Copy from selection buffer */
|
/* Copy from selection buffer */
|
||||||
{ 'p', SEL_CP },
|
{ 'p', SEL_CP },
|
||||||
{ CONTROL('P'), SEL_CP },
|
{ CONTROL('P'), SEL_CP },
|
||||||
@@ -243,7 +243,7 @@ static struct key bindings[] = {
|
@@ -247,7 +247,7 @@ static struct key bindings[] = {
|
||||||
{ 'o', SEL_OPENWITH },
|
{ 'o', SEL_OPENWITH },
|
||||||
{ CONTROL('O'), SEL_OPENWITH },
|
{ CONTROL('O'), SEL_OPENWITH },
|
||||||
/* Create a new file */
|
/* Create a new file */
|
||||||
@ -110,7 +106,7 @@ index 3e4ea19c..b0eb7cdb 100644
|
|||||||
/* Show rename prompt */
|
/* Show rename prompt */
|
||||||
{ CONTROL('R'), SEL_RENAME },
|
{ CONTROL('R'), SEL_RENAME },
|
||||||
/* Rename contents of current dir */
|
/* Rename contents of current dir */
|
||||||
@@ -255,7 +255,7 @@ static struct key bindings[] = {
|
@@ -259,7 +259,7 @@ static struct key bindings[] = {
|
||||||
/* Toggle auto-advance on file open */
|
/* Toggle auto-advance on file open */
|
||||||
{ CONTROL('J'), SEL_AUTONEXT },
|
{ CONTROL('J'), SEL_AUTONEXT },
|
||||||
/* Edit in EDITOR */
|
/* Edit in EDITOR */
|
||||||
|
33
src/nnn.c
33
src/nnn.c
@ -1551,12 +1551,12 @@ static void xdelay(useconds_t delay)
|
|||||||
usleep(delay);
|
usleep(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char confirm_force(bool selection)
|
static char confirm_force(bool selection, bool use_trash)
|
||||||
{
|
{
|
||||||
char str[64];
|
char str[64];
|
||||||
|
|
||||||
snprintf(str, 64, messages[MSG_FORCE_RM],
|
snprintf(str, 64, messages[MSG_FORCE_RM],
|
||||||
g_state.trash ? utils[UTIL_GIO_TRASH] + 4 : utils[UTIL_RM_RF],
|
use_trash ? utils[UTIL_GIO_TRASH] + 4 : utils[UTIL_RM_RF],
|
||||||
(selection ? "selected" : "hovered"));
|
(selection ? "selected" : "hovered"));
|
||||||
|
|
||||||
int r = get_input(str);
|
int r = get_input(str);
|
||||||
@ -1565,7 +1565,7 @@ static char confirm_force(bool selection)
|
|||||||
return '\0'; /* cancel */
|
return '\0'; /* cancel */
|
||||||
if (r == 'y' || r == 'Y')
|
if (r == 'y' || r == 'Y')
|
||||||
return 'f'; /* forceful for rm */
|
return 'f'; /* forceful for rm */
|
||||||
return (g_state.trash ? '\0' : 'i'); /* interactive for rm */
|
return (use_trash ? '\0' : 'i'); /* interactive for rm */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Writes buflen char(s) from buf to a file */
|
/* Writes buflen char(s) from buf to a file */
|
||||||
@ -2548,13 +2548,13 @@ static void opstr(char *buf, char *op)
|
|||||||
snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c '%s \"$0\" \"$@\" . < /dev/tty' < %s", op, selpath);
|
snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c '%s \"$0\" \"$@\" . < /dev/tty' < %s", op, selpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rmmulstr(char *buf)
|
static bool rmmulstr(char *buf, bool use_trash)
|
||||||
{
|
{
|
||||||
char r = confirm_force(TRUE);
|
char r = confirm_force(TRUE, use_trash);
|
||||||
if (!r)
|
if (!r)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!g_state.trash)
|
if (!use_trash)
|
||||||
snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c 'rm -%cr \"$0\" \"$@\" < /dev/tty' < %s",
|
snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c 'rm -%cr \"$0\" \"$@\" < /dev/tty' < %s",
|
||||||
r, selpath);
|
r, selpath);
|
||||||
else
|
else
|
||||||
@ -2565,13 +2565,13 @@ static bool rmmulstr(char *buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Returns TRUE if file is removed, else FALSE */
|
/* Returns TRUE if file is removed, else FALSE */
|
||||||
static bool xrm(char * const fpath)
|
static bool xrm(char * const fpath, bool use_trash)
|
||||||
{
|
{
|
||||||
char r = confirm_force(FALSE);
|
char r = confirm_force(FALSE, use_trash);
|
||||||
if (!r)
|
if (!r)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!g_state.trash) {
|
if (!use_trash) {
|
||||||
char rm_opts[] = "-ir";
|
char rm_opts[] = "-ir";
|
||||||
|
|
||||||
rm_opts[1] = r;
|
rm_opts[1] = r;
|
||||||
@ -2702,8 +2702,8 @@ static bool cpmvrm_selection(enum action sel, char *path)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: /* SEL_RM */
|
default: /* SEL_TRASH, SEL_RM_ONLY */
|
||||||
if (!rmmulstr(g_buf)) {
|
if (!rmmulstr(g_buf, g_state.trash && sel == SEL_TRASH)) {
|
||||||
printmsg(messages[MSG_CANCEL]);
|
printmsg(messages[MSG_CANCEL]);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -5175,8 +5175,8 @@ static void show_help(const char *path)
|
|||||||
"ca Select all%14A Invert sel\n"
|
"ca Select all%14A Invert sel\n"
|
||||||
"9p ^P Copy here%12w ^W Cp/mv sel as\n"
|
"9p ^P Copy here%12w ^W Cp/mv sel as\n"
|
||||||
"9v ^V Move here%15E Edit sel list\n"
|
"9v ^V Move here%15E Edit sel list\n"
|
||||||
"9x ^X Delete%18S Listed sel size\n"
|
"9x ^X Delete or trash%09S Listed sel size\n"
|
||||||
"aEsc Send to FIFO\n"
|
"cX Delete (rm -rf)%07Esc Send to FIFO\n"
|
||||||
"0\n"
|
"0\n"
|
||||||
"1MISC\n"
|
"1MISC\n"
|
||||||
"8Alt ; Select plugin%11= Launch app\n"
|
"8Alt ; Select plugin%11= Launch app\n"
|
||||||
@ -7651,9 +7651,10 @@ nochange:
|
|||||||
case SEL_CP: // fallthrough
|
case SEL_CP: // fallthrough
|
||||||
case SEL_MV: // fallthrough
|
case SEL_MV: // fallthrough
|
||||||
case SEL_CPMVAS: // fallthrough
|
case SEL_CPMVAS: // fallthrough
|
||||||
case SEL_RM:
|
case SEL_TRASH: // fallthrough
|
||||||
|
case SEL_RM_ONLY:
|
||||||
{
|
{
|
||||||
if (sel == SEL_RM) {
|
if (sel == SEL_TRASH || sel == SEL_RM_ONLY) {
|
||||||
r = get_cur_or_sel();
|
r = get_cur_or_sel();
|
||||||
if (!r) {
|
if (!r) {
|
||||||
statusbar(path);
|
statusbar(path);
|
||||||
@ -7664,7 +7665,7 @@ nochange:
|
|||||||
tmp = (listpath && xstrcmp(path, listpath) == 0)
|
tmp = (listpath && xstrcmp(path, listpath) == 0)
|
||||||
? listroot : path;
|
? listroot : path;
|
||||||
mkpath(tmp, pdents[cur].name, newpath);
|
mkpath(tmp, pdents[cur].name, newpath);
|
||||||
if (!xrm(newpath))
|
if (!xrm(newpath, g_state.trash && sel == SEL_TRASH))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
xrmfromsel(tmp, newpath);
|
xrmfromsel(tmp, newpath);
|
||||||
|
@ -96,7 +96,8 @@ enum action {
|
|||||||
SEL_CP,
|
SEL_CP,
|
||||||
SEL_MV,
|
SEL_MV,
|
||||||
SEL_CPMVAS,
|
SEL_CPMVAS,
|
||||||
SEL_RM,
|
SEL_TRASH,
|
||||||
|
SEL_RM_ONLY,
|
||||||
SEL_OPENWITH,
|
SEL_OPENWITH,
|
||||||
SEL_NEW,
|
SEL_NEW,
|
||||||
SEL_RENAME,
|
SEL_RENAME,
|
||||||
@ -239,8 +240,9 @@ static struct key bindings[] = {
|
|||||||
{ 'w', SEL_CPMVAS },
|
{ 'w', SEL_CPMVAS },
|
||||||
{ CONTROL('W'), SEL_CPMVAS },
|
{ CONTROL('W'), SEL_CPMVAS },
|
||||||
/* Delete from selection buffer */
|
/* Delete from selection buffer */
|
||||||
{ 'x', SEL_RM },
|
{ 'x', SEL_TRASH },
|
||||||
{ CONTROL('X'), SEL_RM },
|
{ CONTROL('X'), SEL_TRASH },
|
||||||
|
{ 'X', SEL_RM_ONLY },
|
||||||
/* Open in a custom application */
|
/* Open in a custom application */
|
||||||
{ 'o', SEL_OPENWITH },
|
{ 'o', SEL_OPENWITH },
|
||||||
{ CONTROL('O'), SEL_OPENWITH },
|
{ CONTROL('O'), SEL_OPENWITH },
|
||||||
|
Loading…
Reference in New Issue
Block a user