aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2018-12-01 14:27:05 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2018-12-01 14:27:05 +0530
commitd1b4cc2beb8493237c25b6e7ce49284eb6c874a5 (patch)
tree76e7a90890052c187e2a2b65a1fe89da9553dd13 /src
parentbbe353c6a2717e6b34cdd87b88c5aa78088e203b (diff)
downloadnnn-d1b4cc2beb8493237c25b6e7ce49284eb6c874a5.tar.gz
Add options to force file operations
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/nnn.c b/src/nnn.c
index a519d0d..00e7384 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -476,6 +476,15 @@ static int get_input(const char *prompt)
return r;
}
+static char confirm_force()
+{
+ int r = get_input("use force? ('y/Y' confirms, else interactive)");
+ if (r == 'y' || r == 'Y')
+ return 'f'; /* forceful */
+
+ return 'i'; /* interactive */
+}
+
/* Increase the limit on open file descriptors, if possible */
static rlim_t max_openfds()
{
@@ -3135,36 +3144,38 @@ nochange:
goto nochange;
}
- /* Fail if copy file path isn't created */
+ /* Fail if copy file path isn't accessible */
if (access(g_cppath, R_OK) == -1) {
printmsg("empty selection list");
goto nochange;
}
+ char force = confirm_force();
+
if (sel == SEL_CP) {
snprintf(g_buf, MAX_CMD_LEN,
#ifdef __linux__
- "xargs -0 -a %s -%c src cp -iRp src .",
+ "xargs -0 -a %s -%c src cp -%cRp src .",
#else
- "cat %s | xargs -0 -o -%c src cp -iRp src .",
+ "cat %s | xargs -0 -o -%c src cp -%cRp src .",
#endif
- g_cppath, REPLACE_STR);
+ g_cppath, REPLACE_STR, force);
} else if (sel == SEL_MV) {
snprintf(g_buf, MAX_CMD_LEN,
#ifdef __linux__
- "xargs -0 -a %s -%c src mv -i src .",
+ "xargs -0 -a %s -%c src mv -%c src .",
#else
- "cat %s | xargs -0 -o -%c src mv -i src .",
+ "cat %s | xargs -0 -o -%c src mv -%c src .",
#endif
- g_cppath, REPLACE_STR);
+ g_cppath, REPLACE_STR, force);
} else { /* SEL_RMMUL */
snprintf(g_buf, MAX_CMD_LEN,
#ifdef __linux__
- "xargs -0 -a %s rm -ir",
+ "xargs -0 -a %s rm -%cr",
#else
- "cat %s | xargs -0 -o rm -ir",
+ "cat %s | xargs -0 -o rm -%cr",
#endif
- g_cppath);
+ g_cppath, force);
}
spawn("sh", "-c", g_buf, path, F_NORMAL | F_SIGINT);
@@ -3175,16 +3186,21 @@ nochange:
goto begin;
}
case SEL_RM:
+ {
if (!ndents)
break;
+ char rm_opts[] = "-ir";
+ rm_opts[1] = confirm_force();
+
mkpath(path, dents[cur].name, newpath, PATH_MAX);
- spawn("rm", "-ir", newpath, NULL, F_NORMAL | F_SIGINT);
+ spawn("rm", rm_opts, newpath, NULL, F_NORMAL | F_SIGINT);
- lastname[0] = '\0';
+ copycurname();
if (cfg.filtermode)
presel = FILTER;
goto begin;
+ }
case SEL_OPEN: // fallthrough
case SEL_ARCHIVE:
if (!ndents)