2020-06-20 13:39:32 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2021-05-15 17:32:01 +00:00
|
|
|
# Description: Allows for creation of multiple files/dirs simultaneously
|
|
|
|
# Creates a tmp file to write each entry in a separate line
|
2020-06-20 13:39:32 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2020-11-28 04:33:05 +00:00
|
|
|
EDITOR="${EDITOR:-vi}"
|
2020-06-20 13:39:32 +00:00
|
|
|
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"
|