mirror of
https://github.com/jarun/nnn.git
synced 2024-09-29 09:17:51 +00:00
Batch rename: prompt if selection exists
This commit is contained in:
parent
c3ce5bc705
commit
684a90a0fb
19
src/nnn.c
19
src/nnn.c
|
@ -1220,21 +1220,27 @@ static bool batch_rename(const char *path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!selbufpos) {
|
if (selbufpos) {
|
||||||
|
i = get_input("rename selection? [y/Y confirms]");
|
||||||
|
if (i != 'y' && i != 'Y') {
|
||||||
if (!ndents)
|
if (!ndents)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
for (i = 0; i < ndents; ++i)
|
selbufpos = 0; /* Clear the selection */
|
||||||
appendfpath(dents[i].name, NAME_MAX);
|
|
||||||
|
|
||||||
dir = TRUE;
|
dir = TRUE;
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
dir = TRUE; /* Rename entries in dir */
|
||||||
|
|
||||||
|
if (dir)
|
||||||
|
for (i = 0; i < ndents; ++i)
|
||||||
|
appendfpath(dents[i].name, NAME_MAX);
|
||||||
|
|
||||||
selectiontofd(fd1, &count);
|
selectiontofd(fd1, &count);
|
||||||
selectiontofd(fd2, NULL);
|
selectiontofd(fd2, NULL);
|
||||||
close(fd2);
|
close(fd2);
|
||||||
|
|
||||||
if (dir)
|
if (dir) /* Don't retain dir entries in selection */
|
||||||
selbufpos = 0;
|
selbufpos = 0;
|
||||||
|
|
||||||
spawn(editor, g_tmpfpath, NULL, path, F_CLI);
|
spawn(editor, g_tmpfpath, NULL, path, F_CLI);
|
||||||
|
@ -1243,10 +1249,9 @@ static bool batch_rename(const char *path)
|
||||||
if ((fd2 = open(g_tmpfpath, O_RDONLY)) == -1)
|
if ((fd2 = open(g_tmpfpath, O_RDONLY)) == -1)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
while ((i = read(fd2, buf, sizeof(buf))) > 0) {
|
while ((i = read(fd2, buf, sizeof(buf))) > 0)
|
||||||
while (i)
|
while (i)
|
||||||
lines += (buf[--i] == '\n');
|
lines += (buf[--i] == '\n');
|
||||||
}
|
|
||||||
|
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
Loading…
Reference in a new issue