~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/.config/nnn/plugins/bulknew -rw-r--r-- 739 bytes
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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"