Use a single keybind for cp/mv as

This commit is contained in:
Arun Prakash Jana 2019-10-17 23:35:49 +05:30
parent 522626a88d
commit 2da5602a4f
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 20 additions and 23 deletions

View file

@ -1296,11 +1296,12 @@ static uint lines_in_file(int fd, char *buf, size_t buflen)
return ((len < 0) ? 0 : count); return ((len < 0) ? 0 : count);
} }
static bool cpmv_rename(const char *path, const char *cmd) static bool cpmv_rename(int choice, const char *path)
{ {
int fd; int fd;
uint count = 0, lines = 0; uint count = 0, lines = 0;
bool ret = FALSE; bool ret = FALSE;
char *cmd = (choice == 'c' ? cp : mv);
const char formatcmd[] = "sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s"; const char formatcmd[] = "sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s";
const char renamecmd[] = const char renamecmd[] =
"sed 's|^\\([^#][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' %s | tr '\\n' '\\0' | xargs -0 -o -n2 %s"; "sed 's|^\\([^#][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' %s | tr '\\n' '\\0' | xargs -0 -o -n2 %s";
@ -3065,11 +3066,10 @@ static void show_help(const char *path)
"1FILES\n" "1FILES\n"
"b^O Open with... n Create new/link\n" "b^O Open with... n Create new/link\n"
"cD File detail ^R F2 Rename/duplicate\n" "cD File detail ^R F2 Rename/duplicate\n"
"9⎵ ^J Select entry r Batch rename\n" "7⎵ ^J/a Select entry/all r Batch rename\n"
"9m ^K Sel range, clear M List selection\n" "9m ^K Sel range, clear M List selection\n"
"ca Select all K Edit selection\n" "cP Copy selection K Edit selection\n"
"cP Copy selection w Copy selection as\n" "cV Move selection w Copy/move sel as\n"
"cV Move selection W Move selection as\n"
"cX Del selection ^X Del entry\n" "cX Del selection ^X Del entry\n"
"cf Create archive T Mount archive\n" "cf Create archive T Mount archive\n"
"b^F Extract archive F List archive\n" "b^F Extract archive F List archive\n"
@ -4434,10 +4434,9 @@ nochange:
goto nochange; goto nochange;
} }
break; break;
case SEL_CP: case SEL_CP: // fallthrough
case SEL_MV: case SEL_MV: // fallthrough
case SEL_CPAS: case SEL_CPMVAS: // fallthrough
case SEL_MVAS:
case SEL_RMMUL: case SEL_RMMUL:
{ {
endselection(); endselection();
@ -4454,14 +4453,15 @@ nochange:
case SEL_MV: case SEL_MV:
opstr(g_buf, mv); opstr(g_buf, mv);
break; break;
case SEL_CPAS: case SEL_CPMVAS:
if (!cpmv_rename(path, cp)) { r = get_input("'c'p / 'm'v as?");
printwait(messages[OPERATION_FAILED], &presel); if (r != 'c' && r != 'm') {
if (cfg.filtermode)
presel = FILTER;
goto nochange; goto nochange;
} }
break;
case SEL_MVAS: if (!cpmv_rename(r, path)) {
if (!cpmv_rename(path, mv)) {
printwait(messages[OPERATION_FAILED], &presel); printwait(messages[OPERATION_FAILED], &presel);
goto nochange; goto nochange;
} }
@ -4471,11 +4471,11 @@ nochange:
break; break;
} }
if (sel != SEL_CPAS && sel != SEL_MVAS) if (sel != SEL_CPMVAS)
spawn(utils[SH_EXEC], g_buf, NULL, path, F_CLI); spawn(utils[SH_EXEC], g_buf, NULL, path, F_CLI);
/* Clear selection on move or delete */ /* Clear selection on move or delete */
if (sel == SEL_MV || sel == SEL_MVAS || sel == SEL_RMMUL) if (sel != SEL_CP)
clearselection(); clearselection();
if (ndents) if (ndents)

View file

@ -82,8 +82,7 @@ enum action {
SEL_SELEDIT, SEL_SELEDIT,
SEL_CP, SEL_CP,
SEL_MV, SEL_MV,
SEL_CPAS, SEL_CPMVAS,
SEL_MVAS,
SEL_RMMUL, SEL_RMMUL,
SEL_RM, SEL_RM,
SEL_OPENWITH, SEL_OPENWITH,
@ -219,10 +218,8 @@ static struct key bindings[] = {
{ 'P', SEL_CP }, { 'P', SEL_CP },
/* Move from selection buffer */ /* Move from selection buffer */
{ 'V', SEL_MV }, { 'V', SEL_MV },
/* Copyfrom selection buffer and rename */ /* Copy/move from selection buffer and rename */
{ 'w', SEL_CPAS }, { 'w', SEL_CPMVAS },
/* Movefrom selection buffer and rename */
{ 'W', SEL_MVAS },
/* Delete from selection buffer */ /* Delete from selection buffer */
{ 'X', SEL_RMMUL }, { 'X', SEL_RMMUL },
/* Delete currently selected */ /* Delete currently selected */