mirror of
https://github.com/jarun/nnn.git
synced 2025-03-18 20:39:45 +00:00
make var O_NOBATCH to compile out native batch renamer
This commit is contained in:
parent
54d2580799
commit
a4243edacc
2 changed files with 16 additions and 7 deletions
4
Makefile
4
Makefile
|
@ -51,6 +51,10 @@ ifeq ($(O_NOMOUSE),1)
|
||||||
CPPFLAGS += -DNOMOUSE
|
CPPFLAGS += -DNOMOUSE
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(O_NOBATCH),1)
|
||||||
|
CPPFLAGS += -DNOBATCH
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
|
ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1)
|
||||||
CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
|
CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw)
|
||||||
LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncursesw)
|
LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncursesw)
|
||||||
|
|
19
src/nnn.c
19
src/nnn.c
|
@ -635,16 +635,13 @@ static char mv[] = "mv -i";
|
||||||
/* Patterns */
|
/* Patterns */
|
||||||
#define P_CPMVFMT 0
|
#define P_CPMVFMT 0
|
||||||
#define P_CPMVRNM 1
|
#define P_CPMVRNM 1
|
||||||
#define P_BATCHRNM 2
|
#define P_ARCHIVE 2
|
||||||
#define P_ARCHIVE 3
|
#define P_REPLACE 3
|
||||||
#define P_REPLACE 4
|
|
||||||
|
|
||||||
static const char * const patterns[] = {
|
static const char * const patterns[] = {
|
||||||
"sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s",
|
"sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s",
|
||||||
"sed 's|^\\([^#][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' "
|
"sed 's|^\\([^#][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' "
|
||||||
"%s | tr '\\n' '\\0' | xargs -0 -n2 sh -c '%s \"$0\" \"$@\" < /dev/tty'",
|
"%s | tr '\\n' '\\0' | xargs -0 -n2 sh -c '%s \"$0\" \"$@\" < /dev/tty'",
|
||||||
"paste -d'\n' %s %s | sed 'N; /^\\(.*\\)\\n\\1$/!p;d' | "
|
|
||||||
"tr '\n' '\\0' | xargs -0 -n2 mv 2>/dev/null",
|
|
||||||
"\\.(bz|bz2|gz|tar|taz|tbz|tbz2|tgz|z|zip)$",
|
"\\.(bz|bz2|gz|tar|taz|tbz|tbz2|tgz|z|zip)$",
|
||||||
"sed -i 's|^%s\\(.*\\)$|%s\\1|' %s",
|
"sed -i 's|^%s\\(.*\\)$|%s\\1|' %s",
|
||||||
};
|
};
|
||||||
|
@ -1894,13 +1891,16 @@ static bool cpmvrm_selection(enum action sel, char *path)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NOBATCH
|
||||||
static bool batch_rename(const char *path)
|
static bool batch_rename(const char *path)
|
||||||
{
|
{
|
||||||
int fd1, fd2, i;
|
int fd1, fd2, i;
|
||||||
uint count = 0, lines = 0;
|
uint count = 0, lines = 0;
|
||||||
bool dir = FALSE, ret = FALSE;
|
bool dir = FALSE, ret = FALSE;
|
||||||
char foriginal[TMP_LEN_MAX] = {0};
|
char foriginal[TMP_LEN_MAX] = {0};
|
||||||
char buf[sizeof(patterns[P_BATCHRNM]) + (PATH_MAX << 1)];
|
static const char batchrenamecmd[] = "paste -d'\n' %s %s | sed 'N; /^\\(.*\\)\\n\\1$/!p;d' | "
|
||||||
|
"tr '\n' '\\0' | xargs -0 -n2 mv 2>/dev/null";
|
||||||
|
char buf[sizeof(batchrenamecmd) + (PATH_MAX << 1)];
|
||||||
|
|
||||||
i = get_cur_or_sel();
|
i = get_cur_or_sel();
|
||||||
if (!i)
|
if (!i)
|
||||||
|
@ -1950,7 +1950,7 @@ static bool batch_rename(const char *path)
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), patterns[P_BATCHRNM], foriginal, g_tmpfpath);
|
snprintf(buf, sizeof(buf), batchrenamecmd, foriginal, g_tmpfpath);
|
||||||
spawn(utils[UTIL_SH_EXEC], buf, NULL, path, F_CLI);
|
spawn(utils[UTIL_SH_EXEC], buf, NULL, path, F_CLI);
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
||||||
|
@ -1965,6 +1965,7 @@ finish:
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void get_archive_cmd(char *cmd, const char *archive)
|
static void get_archive_cmd(char *cmd, const char *archive)
|
||||||
{
|
{
|
||||||
|
@ -5708,7 +5709,11 @@ nochange:
|
||||||
|
|
||||||
if (!(getutil(utils[UTIL_BASH])
|
if (!(getutil(utils[UTIL_BASH])
|
||||||
&& plugscript(utils[UTIL_NMV], newpath, path, F_CLI))
|
&& plugscript(utils[UTIL_NMV], newpath, path, F_CLI))
|
||||||
|
#ifndef NOBATCH
|
||||||
&& !batch_rename(path)) {
|
&& !batch_rename(path)) {
|
||||||
|
#else
|
||||||
|
) {
|
||||||
|
#endif
|
||||||
printwait(messages[MSG_FAILED], &presel);
|
printwait(messages[MSG_FAILED], &presel);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue