Support duplicate file/dir

This commit is contained in:
Arun Prakash Jana 2019-08-04 07:32:37 +05:30
parent f7a00ae114
commit 2bfcb281e7
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 9 additions and 4 deletions

View file

@ -122,7 +122,7 @@ Here's a video of [`nnn` on Termux (Android)](https://www.youtube.com/watch?v=Ab
- FreeDesktop compliant trash (needs trash-cli) - FreeDesktop compliant trash (needs trash-cli)
- SSHFS mounts (needs sshfs) - SSHFS mounts (needs sshfs)
- Mouse support - Mouse support
- Create, rename files and directories - Create, rename, duplicate files and directories
- Show copy, move progress on Linux (needs avdcpmv) - Show copy, move progress on Linux (needs avdcpmv)
- Per-context directory color (default: blue) - Per-context directory color (default: blue)
- Spawn a shell in the current directory - Spawn a shell in the current directory
@ -285,7 +285,7 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
Q ^Q Quit ? Help, config Q ^Q Quit ? Help, config
FILES FILES
^O Open with... n Create new/link ^O Open with... n Create new/link
D File details ^R Rename entry D File details ^R Rename/duplicate
⎵ ^K / Y Select entry/all r Batch rename ⎵ ^K / Y Select entry/all r Batch rename
K ^Y Toggle selection y List selection K ^Y Toggle selection y List selection
P Copy selection X Delete selection P Copy selection X Delete selection

View file

@ -2814,7 +2814,7 @@ static bool show_help(const char *path)
"9Q ^Q Quit ? Help, config\n" "9Q ^Q Quit ? Help, config\n"
"1FILES\n" "1FILES\n"
"b^O Open with... n Create new/link\n" "b^O Open with... n Create new/link\n"
"cD File details ^R Rename entry\n" "cD File details ^R Rename/duplicate\n"
"5⎵ ^K / Y Select entry/all r Batch rename\n" "5⎵ ^K / Y Select entry/all r Batch rename\n"
"9K ^Y Toggle selection y List selection\n" "9K ^Y Toggle selection y List selection\n"
"cP Copy selection X Delete selection\n" "cP Copy selection X Delete selection\n"
@ -4160,6 +4160,8 @@ nochange:
case SEL_ARCHIVE: // fallthrough case SEL_ARCHIVE: // fallthrough
case SEL_NEW: case SEL_NEW:
{ {
int dup = 'n';
switch (sel) { switch (sel) {
case SEL_ARCHIVE: case SEL_ARCHIVE:
r = get_input("archive selection (else current)? [y/Y confirms]"); r = get_input("archive selection (else current)? [y/Y confirms]");
@ -4190,6 +4192,7 @@ nochange:
tmp = xreadline(NULL, "name/link suffix [@ for none]: "); tmp = xreadline(NULL, "name/link suffix [@ for none]: ");
break; break;
default: /* SEL_RENAME */ default: /* SEL_RENAME */
dup = get_input("duplicate? [y/Y confirms]");
tmp = xreadline(dents[cur].name, ""); tmp = xreadline(dents[cur].name, "");
break; break;
} }
@ -4274,7 +4277,9 @@ nochange:
if (sel == SEL_RENAME) { if (sel == SEL_RENAME) {
/* Rename the file */ /* Rename the file */
if (renameat(fd, dents[cur].name, fd, tmp) != 0) { if (dup == 'y' || dup == 'Y') {
spawn("cp -r", dents[cur].name, tmp, path, F_CLI | F_NOTRACE);
} else if (renameat(fd, dents[cur].name, fd, tmp) != 0) {
close(fd); close(fd);
printwarn(&presel); printwarn(&presel);
goto nochange; goto nochange;