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

Support more trash utility #1831

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion nnn.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 19 additions & 3 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -591,6 +592,7 @@ static char * const utils[] = {
"gio trash",
"rm -rf --",
"archivemount",
"trash",
};

/* Common strings */
Expand Down Expand Up @@ -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 */
}
Expand Down Expand Up @@ -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 */
Expand Down