Bulk file/directory creation
Jump to navigation
Jump to search
This script enables bulk file/directory creation using a template file for input. It supports nested files and directories. It will replace all space characters in generated dirs with hyphens.
Create a file with the following content and store it on your path (e.g., ~/.local/bin/ or $VIFM/scripts if not planning to use it outside of Vifm):
#!/usr/bin/env bash
TMPDIR="${TMPDIR:-/tmp}"
EDITOR="${EDITOR:-vi}"
gen_file=$(mktemp) || exit
trap 'rm -f "$gen_file"' EXIT
"$EDITOR" "$gen_file" || exit
while IFS= read -r line; do
line="${line/% }"
line="${line// /-}"
if [[ -z $line ]]; then
continue
fi
if [[ $line == */* ]]; then
if [[ $line == */ ]]; then
mkdir -p "$line"
else
mkdir -p "$(dirname "$line")" && touch "$line"
fi
else
touch "$line"
fi
done < "$gen_file"
Then you can bind it in your ~/.config/vifm/vifmrc:
nnoremap <wait> on :!mkbulk<cr>