diff --git a/nyan b/nyan index 697a960..ca6a11f 100755 --- a/nyan +++ b/nyan @@ -1,6 +1,8 @@ #!/bin/bash optstring="o:" -input_files="" +declare -i abort=0 + +# TODO: Check for dependencies pv and stat. while getopts ${optstring} args; do case $args in @@ -8,20 +10,28 @@ while getopts ${optstring} args; do :) echo "Output file required." ;; esac done - shift $((OPTIND-1)) -echo $output_file - echo "Concatenating files..." declare -i total_size=0 for fname in "$@"; do - #TODO: Make sure this file exists and isn't a directory! - current_file_size=$(stat -c%s "$fname") - let total_size=$total_size+$current_file_size - echo "${fname} is ${total_size}b and valid." + if [ ! -e "$fname" ]; then + abort=1 + echo "${fname} does not exist." + elif [ -d "$fname" ]; then + abort=1 + echo "${fname} is a directory." + else + current_file_size=$(stat -c%s "$fname") + total_size=$((total_size+current_file_size)) + # TODO: Use something more legible than bytes. + echo "Adding ${fname} at ${total_size}b." + fi done -cat "$@" | pv -epts "$total_size" > "$output_file" - -echo "Done!" +if [ $abort -eq 0 ]; then + cat "$@" | pv -epts "$total_size" > "$output_file" + echo "Done!" +else + echo "Errors occurred, concatenation aborted." +fi