From afdb10e79f5755a9bef93390a7d9523c8abea9df Mon Sep 17 00:00:00 2001 From: PowerUser64 Date: Fri, 27 May 2022 17:26:13 -0700 Subject: [PATCH] pandoc-make: add error handling for if no files are given --- .config/shell/bin/pandoc-make | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.config/shell/bin/pandoc-make b/.config/shell/bin/pandoc-make index bbdc222..c63f0ab 100755 --- a/.config/shell/bin/pandoc-make +++ b/.config/shell/bin/pandoc-make @@ -60,12 +60,12 @@ for FILE in "$@";do # Guard against overwriting md files and tex files if { [[ "$OUTPUT_FORMAT" = md ]] || [[ "$OUTPUT_FORMAT" = tex ]]; } && [[ -f "$OUTPUT_FILE" ]]; then if confirm "Overwrite $FILE? [y/N]: "; then - # Make new file names until there is no overwriting while [[ -f "$OUTPUT_FILE" ]]; do OUTPUT_FILE="${FILE%.*}-$((FILE_NUM++)).${OUTPUT_FORMAT##.}" done echo "Not overwriting, new name: '$OUTPUT_FILE'" + else # Give some time to ctrl-c before overwrite… SLEEP_DURATION=1 @@ -87,4 +87,10 @@ for FILE in "$@";do fi 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