mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Integrate batch renamer plugin
This commit is contained in:
parent
29fe67b799
commit
f527dd1c6a
|
@ -78,7 +78,7 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/watch?v=AbaauM7gUJw
|
||||||
- Run plugins and custom commands with hotkeys
|
- Run plugins and custom commands with hotkeys
|
||||||
- FreeDesktop compliant trash (needs trash-cli)
|
- FreeDesktop compliant trash (needs trash-cli)
|
||||||
- Cross-dir file/all/range selection
|
- Cross-dir file/all/range selection
|
||||||
- Batch renamer (feature-limited) for selection or dir
|
- Batch renamer for selection or dir
|
||||||
- Display a list of files from stdin
|
- Display a list of files from stdin
|
||||||
- Copy (as), move (as), delete, archive, link selection
|
- Copy (as), move (as), delete, archive, link selection
|
||||||
- Dir updates, notification on cp, mv, rm completion
|
- Dir updates, notification on cp, mv, rm completion
|
||||||
|
|
|
@ -27,7 +27,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`.
|
||||||
| Plugin (a-z) | Description | Lang | Deps |
|
| Plugin (a-z) | Description | Lang | Deps |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| autojump | Navigate to dir/path (**autojump stores navigation patterns**) | sh | autojump |
|
| autojump | Navigate to dir/path (**autojump stores navigation patterns**) | sh | autojump |
|
||||||
| batchrename | Batch file renamer | sh | mktemp |
|
| batchrename | Batch rename selection or dir entries | sh | mktemp |
|
||||||
| boom | Play random music from dir | sh | [moc](http://moc.daper.net/) |
|
| boom | Play random music from dir | sh | [moc](http://moc.daper.net/) |
|
||||||
| dups | List non-empty duplicate files in current dir | sh | find, md5sum,<br>sort uniq xargs |
|
| dups | List non-empty duplicate files in current dir | sh | find, md5sum,<br>sort uniq xargs |
|
||||||
| chksum | Create and verify checksums | sh | md5sum,<br>sha256sum |
|
| chksum | Create and verify checksums | sh | md5sum,<br>sha256sum |
|
||||||
|
|
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
# Description: An almost fully POSIX compliant batch file renamer
|
# Description: An almost fully POSIX compliant batch file renamer
|
||||||
#
|
#
|
||||||
|
# Note: nnn auto-detects and invokes this plugin if available
|
||||||
|
#
|
||||||
|
# Capabilities:
|
||||||
|
# 1. Basic file rename
|
||||||
|
# 2. Detects order change
|
||||||
|
# 3. Can move files
|
||||||
|
# 4. Can remove files
|
||||||
|
# 5. Switch number pairs to swap filenames
|
||||||
|
#
|
||||||
# Shell: POSIX compliant
|
# Shell: POSIX compliant
|
||||||
# Author: KlzXS
|
# Author: KlzXS
|
||||||
|
|
||||||
|
|
25
src/nnn.c
25
src/nnn.c
|
@ -431,6 +431,7 @@ static uchar g_states;
|
||||||
#define UTIL_FZY 16
|
#define UTIL_FZY 16
|
||||||
#define UTIL_NTFY 17
|
#define UTIL_NTFY 17
|
||||||
#define UTIL_CBCP 18
|
#define UTIL_CBCP 18
|
||||||
|
#define UTIL_BATCHRENAME 19
|
||||||
|
|
||||||
/* Utilities to open files, run actions */
|
/* Utilities to open files, run actions */
|
||||||
static char * const utils[] = {
|
static char * const utils[] = {
|
||||||
|
@ -469,6 +470,7 @@ static char * const utils[] = {
|
||||||
"fzy",
|
"fzy",
|
||||||
".ntfy",
|
".ntfy",
|
||||||
".cbcp",
|
".cbcp",
|
||||||
|
"batchrename",
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Common strings */
|
/* Common strings */
|
||||||
|
@ -681,7 +683,7 @@ static void move_cursor(int target, int ignore_scrolloff);
|
||||||
static inline bool getutil(char *util);
|
static inline bool getutil(char *util);
|
||||||
static size_t mkpath(const char *dir, const char *name, char *out);
|
static size_t mkpath(const char *dir, const char *name, char *out);
|
||||||
static char *xgetenv(const char *name, char *fallback);
|
static char *xgetenv(const char *name, char *fallback);
|
||||||
static void plugscript(const char *plugin, char *newpath, uchar flags);
|
static bool plugscript(const char *plugin, char *newpath, const char *path, uchar flags);
|
||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
|
|
||||||
|
@ -4206,11 +4208,15 @@ static bool run_selected_plugin(char **path, const char *file, char *newpath, ch
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void plugscript(const char *plugin, char *newpath, uchar flags)
|
static bool plugscript(const char *plugin, char *newpath, const char *path, uchar flags)
|
||||||
{
|
{
|
||||||
mkpath(plugindir, plugin, newpath);
|
mkpath(plugindir, plugin, newpath);
|
||||||
if (!access(newpath, X_OK))
|
if (!access(newpath, X_OK)) {
|
||||||
spawn(newpath, NULL, NULL, NULL, flags);
|
spawn(newpath, NULL, NULL, path, flags);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void launch_app(const char *path, char *newpath)
|
static void launch_app(const char *path, char *newpath)
|
||||||
|
@ -5601,7 +5607,8 @@ nochange:
|
||||||
case SEL_RENAMEMUL:
|
case SEL_RENAMEMUL:
|
||||||
endselection();
|
endselection();
|
||||||
|
|
||||||
if (!batch_rename(path)) {
|
if (!plugscript(utils[UTIL_BATCHRENAME], newpath, path, F_CLI)
|
||||||
|
&& !batch_rename(path)) {
|
||||||
printwait(messages[MSG_FAILED], &presel);
|
printwait(messages[MSG_FAILED], &presel);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
@ -5657,7 +5664,7 @@ nochange:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.x11)
|
if (cfg.x11)
|
||||||
plugscript(utils[UTIL_CBCP], newpath, F_NOWAIT | F_NOTRACE);
|
plugscript(utils[UTIL_CBCP], newpath, NULL, F_NOWAIT | F_NOTRACE);
|
||||||
|
|
||||||
if (!nselected)
|
if (!nselected)
|
||||||
unlink(selpath);
|
unlink(selpath);
|
||||||
|
@ -5733,7 +5740,7 @@ nochange:
|
||||||
|
|
||||||
writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
|
writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
|
||||||
if (cfg.x11)
|
if (cfg.x11)
|
||||||
plugscript(utils[UTIL_CBCP], newpath, F_NOWAIT | F_NOTRACE);
|
plugscript(utils[UTIL_CBCP], newpath, NULL, F_NOWAIT | F_NOTRACE);
|
||||||
continue;
|
continue;
|
||||||
case SEL_SELEDIT:
|
case SEL_SELEDIT:
|
||||||
r = editselection();
|
r = editselection();
|
||||||
|
@ -5742,7 +5749,7 @@ nochange:
|
||||||
printwait(messages[r], &presel);
|
printwait(messages[r], &presel);
|
||||||
} else {
|
} else {
|
||||||
if (cfg.x11)
|
if (cfg.x11)
|
||||||
plugscript(utils[UTIL_CBCP], newpath, F_NOWAIT | F_NOTRACE);
|
plugscript(utils[UTIL_CBCP], newpath, NULL, F_NOWAIT | F_NOTRACE);
|
||||||
cfg.filtermode ? presel = FILTER : statusbar(path);
|
cfg.filtermode ? presel = FILTER : statusbar(path);
|
||||||
}
|
}
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
@ -5788,7 +5795,7 @@ nochange:
|
||||||
|
|
||||||
/* Show notification on operation complete */
|
/* Show notification on operation complete */
|
||||||
if (cfg.x11)
|
if (cfg.x11)
|
||||||
plugscript(utils[UTIL_NTFY], newpath, F_NOWAIT | F_NOTRACE);
|
plugscript(utils[UTIL_NTFY], newpath, NULL, F_NOWAIT | F_NOTRACE);
|
||||||
|
|
||||||
if (ndents)
|
if (ndents)
|
||||||
copycurname();
|
copycurname();
|
||||||
|
|
Loading…
Reference in a new issue