From ceb94e276692a9680e45e012577293a6c6321cac Mon Sep 17 00:00:00 2001 From: Bojun Ren Date: Sun, 25 Feb 2024 16:19:04 +0800 Subject: [PATCH 1/2] support macos-trash Support sindresorhus/macos-trash, which just moves files/folders to the macOS native trash bin. Setting `NNN_TRASH=3` makes nnn use `trash` command to delete files. --- src/nnn.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/nnn.c b/src/nnn.c index 416e0ca83..8191e456d 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -550,6 +550,7 @@ static runstate g_state; #define UTIL_GIO_TRASH 19 #define UTIL_RM_RF 20 #define UTIL_ARCHMNT 21 +#define UTIL_TRASH 22 /* Utilities to open files, run actions */ static char * const utils[] = { @@ -591,6 +592,7 @@ static char * const utils[] = { "gio trash", "rm -rf --", "archivemount", + "trash", }; /* Common strings */ @@ -2577,9 +2579,23 @@ static bool xrm(char * const fpath, bool use_trash) rm_opts[1] = r; spawn("rm", rm_opts, "--", fpath, F_NORMAL | F_CHKRTN); - } else - spawn(utils[(g_state.trash == 1) ? UTIL_TRASH_CLI : UTIL_GIO_TRASH], + } else { + uint trash_util_idx; + switch(g_state.trash) { + case 1: + trash_util_idx = UTIL_TRASH_CLI; + break; + case 2: + trash_util_idx = UTIL_GIO_TRASH; + break; + case 3: + default: + trash_util_idx = UTIL_TRASH; + break; + } + spawn(utils[trash_util_idx], fpath, NULL, NULL, F_NORMAL | F_MULTI); + } return (access(fpath, F_OK) == -1); /* File is removed */ } @@ -8937,7 +8953,7 @@ int main(int argc, char *argv[]) /* Configure trash preference */ opt = xgetenv_val(env_cfg[NNN_TRASH]); - if (opt && opt <= 2) + if (opt && opt <= 3) g_state.trash = opt; /* Ignore/handle certain signals */ From a7b777dffb20f0cf6c8620a0b35317d2425bc990 Mon Sep 17 00:00:00 2001 From: Bojun Ren Date: Sun, 25 Feb 2024 17:10:04 +0800 Subject: [PATCH 2/2] update man page --- nnn.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nnn.1 b/nnn.1 index d4a060449..8a24b5d25 100644 --- a/nnn.1 +++ b/nnn.1 @@ -562,7 +562,7 @@ separated by \fI;\fR: \fBNNN_TRASH:\fR trash (instead of \fIrm -rf\fR) files to desktop Trash. .Bd -literal export NNN_TRASH=n - # n=1: trash-cli, n=2: gio trash + # n=1: trash-cli, n=2: gio trash, n=3: sindresorhus/macos-trash .Ed .Pp \fBNNN_SEL:\fR absolute path to custom selection file.