mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Fix #740
This commit is contained in:
parent
55f2a0823a
commit
1d903a8c90
5
nnn.1
5
nnn.1
|
@ -488,9 +488,10 @@ separated by \fI;\fR:
|
||||||
NOTE: The options must be preceded by "rclone" and max 5 flags are supported.
|
NOTE: The options must be preceded by "rclone" and max 5 flags are supported.
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_TRASH:\fR trash (instead of \fIdelete\fR) files to desktop Trash.
|
\fBNNN_TRASH:\fR trash (instead of \fIrm -rf\fR) files to desktop Trash.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
export NNN_TRASH=1
|
export NNN_TRASH=n
|
||||||
|
# n=1: trash-cli, n=2: gio trash
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_SEL:\fR absolute path to custom selection file.
|
\fBNNN_SEL:\fR absolute path to custom selection file.
|
||||||
|
|
37
src/nnn.c
37
src/nnn.c
|
@ -312,7 +312,7 @@ typedef struct {
|
||||||
uint move : 1; /* Move operation */
|
uint move : 1; /* Move operation */
|
||||||
uint autonext : 1; /* Auto-proceed on open */
|
uint autonext : 1; /* Auto-proceed on open */
|
||||||
uint fortune : 1; /* Show fortune messages in help */
|
uint fortune : 1; /* Show fortune messages in help */
|
||||||
uint trash : 1; /* Use trash to delete files */
|
uint trash : 2; /* Use trash to delete files 1: trash-cli, 2: gio trash */
|
||||||
uint forcequit : 1; /* Do not prompt on quit */
|
uint forcequit : 1; /* Do not prompt on quit */
|
||||||
uint autofifo : 1; /* Auto-create NNN_FIFO */
|
uint autofifo : 1; /* Auto-create NNN_FIFO */
|
||||||
uint initfile : 1; /* Positional arg is a file */
|
uint initfile : 1; /* Positional arg is a file */
|
||||||
|
@ -325,7 +325,7 @@ typedef struct {
|
||||||
uint oldcolor : 1; /* Use older colorscheme */
|
uint oldcolor : 1; /* Use older colorscheme */
|
||||||
uint stayonsel : 1; /* Disable auto-proceed on select */
|
uint stayonsel : 1; /* Disable auto-proceed on select */
|
||||||
uint dirctx : 1; /* Show dirs in context color */
|
uint dirctx : 1; /* Show dirs in context color */
|
||||||
uint reserved : 12; /* Adjust when adding/removing a field */
|
uint reserved : 11; /* Adjust when adding/removing a field */
|
||||||
} runstate;
|
} runstate;
|
||||||
|
|
||||||
/* Contexts or workspaces */
|
/* Contexts or workspaces */
|
||||||
|
@ -1971,14 +1971,14 @@ static char *xgetenv(const char * const name, char *fallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Checks if an env variable is set to 1 */
|
/* Checks if an env variable is set to 1 */
|
||||||
static inline bool xgetenv_set(const char *name)
|
static uint xgetenv_val(const char *name)
|
||||||
{
|
{
|
||||||
char *value = getenv(name);
|
char *str = getenv(name);
|
||||||
|
|
||||||
if (value && value[0] == '1' && !value[1])
|
if (str && str[0])
|
||||||
return TRUE;
|
return atoi(str);
|
||||||
|
|
||||||
return FALSE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if a dir exists, IS a dir and is readable */
|
/* Check if a dir exists, IS a dir and is readable */
|
||||||
|
@ -2003,9 +2003,7 @@ static void opstr(char *buf, char *op)
|
||||||
|
|
||||||
static bool rmmulstr(char *buf)
|
static bool rmmulstr(char *buf)
|
||||||
{
|
{
|
||||||
if (g_state.trash)
|
if (!g_state.trash) {
|
||||||
snprintf(buf, CMD_LEN_MAX, "xargs -0 trash-put < %s", selpath);
|
|
||||||
else {
|
|
||||||
char r = confirm_force(TRUE);
|
char r = confirm_force(TRUE);
|
||||||
|
|
||||||
if (!r)
|
if (!r)
|
||||||
|
@ -2013,7 +2011,10 @@ static bool rmmulstr(char *buf)
|
||||||
|
|
||||||
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 if (g_state.trash == 1)
|
||||||
|
snprintf(buf, CMD_LEN_MAX, "xargs -0 trash-put < %s", selpath);
|
||||||
|
else
|
||||||
|
snprintf(buf, CMD_LEN_MAX, "xargs -0 gio trash < %s", selpath);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -2021,9 +2022,7 @@ 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 *fpath)
|
static bool xrm(char *fpath)
|
||||||
{
|
{
|
||||||
if (g_state.trash)
|
if (!g_state.trash) {
|
||||||
spawn("trash-put", fpath, NULL, F_NORMAL);
|
|
||||||
else {
|
|
||||||
char rm_opts[] = "-ir";
|
char rm_opts[] = "-ir";
|
||||||
|
|
||||||
rm_opts[1] = confirm_force(FALSE);
|
rm_opts[1] = confirm_force(FALSE);
|
||||||
|
@ -2031,7 +2030,10 @@ static bool xrm(char *fpath)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
spawn("rm", rm_opts, fpath, F_NORMAL | F_CHKRTN);
|
spawn("rm", rm_opts, fpath, F_NORMAL | F_CHKRTN);
|
||||||
}
|
} else if (g_state.trash == 1)
|
||||||
|
spawn("trash-put", fpath, NULL, F_NORMAL);
|
||||||
|
else
|
||||||
|
spawn("gio trash", fpath, NULL, F_NORMAL | F_MULTI);
|
||||||
|
|
||||||
return (access(fpath, F_OK) == -1); /* File is removed */
|
return (access(fpath, F_OK) == -1); /* File is removed */
|
||||||
}
|
}
|
||||||
|
@ -7768,8 +7770,9 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Configure trash preference */
|
/* Configure trash preference */
|
||||||
if (xgetenv_set(env_cfg[NNN_TRASH]))
|
opt = xgetenv_val(env_cfg[NNN_TRASH]);
|
||||||
g_state.trash = 1;
|
if (opt && opt <= 2)
|
||||||
|
g_state.trash = opt;
|
||||||
|
|
||||||
/* Ignore/handle certain signals */
|
/* Ignore/handle certain signals */
|
||||||
struct sigaction act = {.sa_handler = sigint_handler};
|
struct sigaction act = {.sa_handler = sigint_handler};
|
||||||
|
|
Loading…
Reference in a new issue