bulknew (736B)
1 #!/usr/bin/env sh 2 3 # Description: Allows for creation of multiple files/dirs simultaneously 4 # Creates a tmp file to write each entry in a separate line 5 # 6 # Note: Only relative paths are supported. Absolute paths are ignored 7 # Leading and trailing whitespace in path names is also ignored 8 # 9 # Shell: POSIX compliant 10 # Author: KlzXS 11 12 EDITOR="${EDITOR:-vi}" 13 TMPDIR="${TMPDIR:-/tmp}" 14 15 printf "'f'ile / 'd'ir? " 16 read -r resp 17 18 if [ "$resp" = "f" ]; then 19 #shellcheck disable=SC2016 20 cmd='mkdir -p "$(dirname "{}")" && touch "{}"' 21 elif [ "$resp" = "d" ]; then 22 cmd='mkdir -p {}' 23 else 24 exit 1 25 fi 26 27 tmpfile=$(mktemp "$TMPDIR/.nnnXXXXXX") 28 $EDITOR "$tmpfile" 29 30 sed "/^\//d" "$tmpfile" | xargs -n1 -I{} sh -c "$cmd" 31 32 rm "$tmpfile"