Add option to `rm -rf` irrespective of trash setting

This commit is contained in:
90 2024-02-09 15:37:22 +00:00 committed by Arun Prakash Jana
parent 94aeaccdbd
commit eb3888cb09
No known key found for this signature in database
GPG Key ID: 4A865183AF6C5631
3 changed files with 34 additions and 35 deletions

View File

@ -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
index 21a7370b..2ddb4053 100644
index 6792d503..0a59e8e3 100644
--- a/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"
"0\n"
"1NAVIGATION\n"
@ -24,7 +20,7 @@ index 21a7370b..2ddb4053 100644
"8B (,) Book(mark)%11b ^/ Select bookmark\n"
"a1-4 Context%11(Sh)Tab Cycle/new context\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"
"0\n"
"1FILTER & PROMPT\n"
@ -46,14 +42,14 @@ index 21a7370b..2ddb4053 100644
"9p ^P Copy here%12w ^W Cp/mv sel as\n"
- "9v ^V Move here%15E Edit sel list\n"
+ "9v ^V Move here%15l Edit sel list\n"
"9x ^X Delete%18S Listed sel size\n"
"aEsc Send to FIFO\n"
"9x ^X Delete or trash%09S Listed sel size\n"
"cX Delete (rm -rf)%07Esc Send to FIFO\n"
"0\n"
diff --git a/src/nnn.h b/src/nnn.h
index 3e4ea19c..b0eb7cdb 100644
index bd500244..b12df5c0 100644
--- a/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 },
/* Pure navigate inside */
{ KEY_RIGHT, SEL_NAV_IN },
@ -69,7 +65,7 @@ index 3e4ea19c..b0eb7cdb 100644
{ KEY_UP, SEL_PREV },
/* Page down */
{ KEY_NPAGE, SEL_PGDN },
@@ -155,11 +155,11 @@ static struct key bindings[] = {
@@ -157,11 +157,11 @@ static struct key bindings[] = {
/* First entry */
{ KEY_HOME, SEL_HOME },
{ 'g', SEL_HOME },
@ -83,7 +79,7 @@ index 3e4ea19c..b0eb7cdb 100644
/* Go to first file */
{ '\'', SEL_FIRST },
/* Jump to an entry number/offset */
@@ -199,7 +199,7 @@ static struct key bindings[] = {
@@ -202,7 +202,7 @@ static struct key bindings[] = {
/* Filter */
{ '/', SEL_FLTR },
/* Toggle filter mode */
@ -92,7 +88,7 @@ index 3e4ea19c..b0eb7cdb 100644
/* Toggle hide .dot files */
{ '.', SEL_HIDDEN },
/* Detailed listing */
@@ -226,7 +226,7 @@ static struct key bindings[] = {
@@ -229,7 +229,7 @@ static struct key bindings[] = {
/* Invert selection in current dir */
{ 'A', SEL_SELINV },
/* List, edit selection */
@ -101,7 +97,7 @@ index 3e4ea19c..b0eb7cdb 100644
/* Copy from selection buffer */
{ '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 },
{ CONTROL('O'), SEL_OPENWITH },
/* Create a new file */
@ -110,7 +106,7 @@ index 3e4ea19c..b0eb7cdb 100644
/* Show rename prompt */
{ CONTROL('R'), SEL_RENAME },
/* 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 */
{ CONTROL('J'), SEL_AUTONEXT },
/* Edit in EDITOR */

View File

@ -1551,12 +1551,12 @@ static void xdelay(useconds_t delay)
usleep(delay);
}
static char confirm_force(bool selection)
static char confirm_force(bool selection, bool use_trash)
{
char str[64];
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"));
int r = get_input(str);
@ -1565,7 +1565,7 @@ static char confirm_force(bool selection)
return '\0'; /* cancel */
if (r == 'y' || r == 'Y')
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 */
@ -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);
}
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)
return FALSE;
if (!g_state.trash)
if (!use_trash)
snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c 'rm -%cr \"$0\" \"$@\" < /dev/tty' < %s",
r, selpath);
else
@ -2565,13 +2565,13 @@ static bool rmmulstr(char *buf)
}
/* 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)
return FALSE;
if (!g_state.trash) {
if (!use_trash) {
char rm_opts[] = "-ir";
rm_opts[1] = r;
@ -2702,8 +2702,8 @@ static bool cpmvrm_selection(enum action sel, char *path)
return FALSE;
}
break;
default: /* SEL_RM */
if (!rmmulstr(g_buf)) {
default: /* SEL_TRASH, SEL_RM_ONLY */
if (!rmmulstr(g_buf, g_state.trash && sel == SEL_TRASH)) {
printmsg(messages[MSG_CANCEL]);
return FALSE;
}
@ -5175,8 +5175,8 @@ static void show_help(const char *path)
"ca Select all%14A Invert sel\n"
"9p ^P Copy here%12w ^W Cp/mv sel as\n"
"9v ^V Move here%15E Edit sel list\n"
"9x ^X Delete%18S Listed sel size\n"
"aEsc Send to FIFO\n"
"9x ^X Delete or trash%09S Listed sel size\n"
"cX Delete (rm -rf)%07Esc Send to FIFO\n"
"0\n"
"1MISC\n"
"8Alt ; Select plugin%11= Launch app\n"
@ -7651,9 +7651,10 @@ nochange:
case SEL_CP: // fallthrough
case SEL_MV: // 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();
if (!r) {
statusbar(path);
@ -7664,7 +7665,7 @@ nochange:
tmp = (listpath && xstrcmp(path, listpath) == 0)
? listroot : path;
mkpath(tmp, pdents[cur].name, newpath);
if (!xrm(newpath))
if (!xrm(newpath, g_state.trash && sel == SEL_TRASH))
continue;
xrmfromsel(tmp, newpath);

View File

@ -96,7 +96,8 @@ enum action {
SEL_CP,
SEL_MV,
SEL_CPMVAS,
SEL_RM,
SEL_TRASH,
SEL_RM_ONLY,
SEL_OPENWITH,
SEL_NEW,
SEL_RENAME,
@ -239,8 +240,9 @@ static struct key bindings[] = {
{ 'w', SEL_CPMVAS },
{ CONTROL('W'), SEL_CPMVAS },
/* Delete from selection buffer */
{ 'x', SEL_RM },
{ CONTROL('X'), SEL_RM },
{ 'x', SEL_TRASH },
{ CONTROL('X'), SEL_TRASH },
{ 'X', SEL_RM_ONLY },
/* Open in a custom application */
{ 'o', SEL_OPENWITH },
{ CONTROL('O'), SEL_OPENWITH },