Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to rm -rf irrespective of trash #1811

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions patches/colemak/mainline.diff
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down
33 changes: 17 additions & 16 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -7651,9 +7651,10 @@ static bool browse(char *ipath, const char *session, int pkey)
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);
Expand All @@ -7664,7 +7665,7 @@ static bool browse(char *ipath, const char *session, int pkey)
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);
Expand Down
8 changes: 5 additions & 3 deletions src/nnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 },
Expand Down
Loading