aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGravatar José Luis Neder <jlneder@gmail.com>2019-12-03 10:00:44 -0300
committerGravatar Mischievous Meerkat <engineerarun@gmail.com>2019-12-03 18:30:44 +0530
commit189042d2d906c386f62939e6dec458d9ccd37052 (patch)
tree1af8f8728aa95a7721272b325d0369281b7cb2b5 /plugins
parentf80563e16a981deeaca43e17b48dbf6ca0ed0efd (diff)
downloadnnn-189042d2d906c386f62939e6dec458d9ccd37052.tar.gz
Plugin renamer (#393)
This plugin is an alternative to the native batch rename interface in nnn. qmv from renameutils and vidir from moreutils allow to rename files without fear of replacing existing files.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/README.md1
-rwxr-xr-xplugins/renamer41
2 files changed, 42 insertions, 0 deletions
diff --git a/plugins/README.md b/plugins/README.md
index cb5b897..17f5750 100644
--- a/plugins/README.md
+++ b/plugins/README.md
@@ -14,6 +14,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
| Plugin (a-z) | Description | Lang | Deps |
| --- | --- | --- | --- |
+| renamer | Batch rename files with qmv or vidir | sh | [renameutils](https://www.nongnu.org/renameutils/) or [moreutils](https://joeyh.name/code/moreutils/) |
| 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 |
| chksum | Create and verify checksums | sh | md5sum,<br>sha256sum |
diff --git a/plugins/renamer b/plugins/renamer
new file mode 100755
index 0000000..5dc8271
--- /dev/null
+++ b/plugins/renamer
@@ -0,0 +1,41 @@
+#!/usr/bin/env sh
+
+# Description: Batch rename selection or current directory with qmv
+#
+# Notes:
+# - Try to mimic current batch rename functionality but with correct
+# handling of edge cases by qmv or vidir.
+# Qmv opens with hidden files if no selection is used. Selected
+# directories are shown.
+# Vidir don't show directories nor hidden files.
+#
+# Shell: POSIX compliant
+# Author: José Neder
+
+selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
+
+if command -v qmv >/dev/null 2>&1; then
+ batchrenamesel="qmv -fdo -da"
+ batchrename="qmv -fdo -a"
+elif command -v vidir >/dev/null 2>&1; then
+ batchrenamesel="vidir"
+ batchrename="vidir"
+else
+ printf "there is not batchrename program installed."
+ exit
+fi
+
+if [ -s "$selection" ]; then
+ printf "rename selection? "
+ read -r resp
+fi
+
+if [ "$resp" = "y" ]; then
+ # -o flag is necessary for interative editors
+ xargs -o -0 $batchrenamesel < "$selection"
+elif [ ! "$(LC_ALL=C ls -a)" = ".
+.." ]; then
+ # On older systems that don't have ls -A
+ $batchrename
+fi
+