diff options
author | KlzXS <azszwymmvqdi@yahoo.com> | 2020-06-20 13:39:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-20 15:39:32 +0200 |
commit | 6147dc9a85d2a54aff3d735d6a7c88d18a8b4f1d (patch) | |
tree | 3235528b048382e6551d111dd2bfaa11526e4fe8 /plugins/bulknew | |
parent | 28bf18adab7be6d665df6eeb3db66a944727bc05 (diff) | |
download | nnn-6147dc9a85d2a54aff3d735d6a7c88d18a8b4f1d.tar.gz |
Add plugin bulknew (#662)
* Add plugin bulknew
* Update documentation
* Update dependencies
* Add whitespace note
Diffstat (limited to 'plugins/bulknew')
-rwxr-xr-x | plugins/bulknew | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/bulknew b/plugins/bulknew new file mode 100755 index 0000000..4010662 --- /dev/null +++ b/plugins/bulknew @@ -0,0 +1,32 @@ +#!/usr/bin/env sh + +# Description: Allows for creation of multiple files/directories at the same time. +# Plugin opens a temp file where each entry is to be written on 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" |