aboutsummaryrefslogtreecommitdiff
path: root/files/.config/nnn/plugins/bulknew
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2023-10-25 19:17:11 +0500
committerAnton Bobov <anton@bobov.name>2023-10-27 14:26:55 +0500
commit62c95ef2f3a2374ddda52302d54801cfe442484d (patch)
tree8b74bb0bee41cf62bc9149429dac7b0f81123919 /files/.config/nnn/plugins/bulknew
parent748cafebaf85b9827c8d3df4535a1a34ddbe82fd (diff)
[nnn] Add getplugs plugin and update all plugins
Diffstat (limited to 'files/.config/nnn/plugins/bulknew')
-rwxr-xr-xfiles/.config/nnn/plugins/bulknew32
1 files changed, 32 insertions, 0 deletions
diff --git a/files/.config/nnn/plugins/bulknew b/files/.config/nnn/plugins/bulknew
new file mode 100755
index 0000000..64331e4
--- /dev/null
+++ b/files/.config/nnn/plugins/bulknew
@@ -0,0 +1,32 @@
+#!/usr/bin/env sh
+
+# Description: Allows for creation of multiple files/dirs simultaneously
+# Creates a tmp file to write each entry in a separate line
+#
+# Note: Only relative paths are supported. Absolute paths are ignored
+# Leading and trailing whitespace in path names is also ignored
+#
+# Shell: POSIX compliant
+# Author: KlzXS
+
+EDITOR="${EDITOR:-vi}"
+TMPDIR="${TMPDIR:-/tmp}"
+
+printf "'f'ile / 'd'ir? "
+read -r resp
+
+if [ "$resp" = "f" ]; then
+ #shellcheck disable=SC2016
+ cmd='mkdir -p "$(dirname "{}")" && touch "{}"'
+elif [ "$resp" = "d" ]; then
+ cmd='mkdir -p {}'
+else
+ exit 1
+fi
+
+tmpfile=$(mktemp "$TMPDIR/.nnnXXXXXX")
+$EDITOR "$tmpfile"
+
+sed "/^\//d" "$tmpfile" | xargs -n1 -I{} sh -c "$cmd"
+
+rm "$tmpfile"