pandoc-make: add error handling for if no files are given

This commit is contained in:
PowerUser64 2022-05-27 17:26:13 -07:00
parent 152a960d9c
commit afdb10e79f

View file

@ -60,12 +60,12 @@ for FILE in "$@";do
# Guard against overwriting md files and tex files # Guard against overwriting md files and tex files
if { [[ "$OUTPUT_FORMAT" = md ]] || [[ "$OUTPUT_FORMAT" = tex ]]; } && [[ -f "$OUTPUT_FILE" ]]; then if { [[ "$OUTPUT_FORMAT" = md ]] || [[ "$OUTPUT_FORMAT" = tex ]]; } && [[ -f "$OUTPUT_FILE" ]]; then
if confirm "Overwrite $FILE? [y/N]: "; then if confirm "Overwrite $FILE? [y/N]: "; then
# Make new file names until there is no overwriting # Make new file names until there is no overwriting
while [[ -f "$OUTPUT_FILE" ]]; do while [[ -f "$OUTPUT_FILE" ]]; do
OUTPUT_FILE="${FILE%.*}-$((FILE_NUM++)).${OUTPUT_FORMAT##.}" OUTPUT_FILE="${FILE%.*}-$((FILE_NUM++)).${OUTPUT_FORMAT##.}"
done done
echo "Not overwriting, new name: '$OUTPUT_FILE'" echo "Not overwriting, new name: '$OUTPUT_FILE'"
else else
# Give some time to ctrl-c before overwrite… # Give some time to ctrl-c before overwrite…
SLEEP_DURATION=1 SLEEP_DURATION=1
@ -87,4 +87,10 @@ for FILE in "$@";do
fi fi
done done
# Error if no files were processed
if [ -z "$OUTPUT_FILE" ]; then
echo "Error: no files to process were found" >&2
exit 1
fi
# vim:et ts=3 sw=3 # vim:et ts=3 sw=3