[READ-ONLY] Mirror of https://github.com/probablykasper/my-bash-scripts. My personal bash scripts
cli
0

Configure Feed

Select the types of activity you want to include in your feed.

Rewritten "render", now works with multiple files

Kasper (Apr 13, 2019, 7:47 PM +0200) e4f8a2c5 16ec88cc

+67 -38
+67 -38
bin/render
··· 1 1 #! /bin/bash 2 2 3 + color() { 4 + echo -n "`tput setaf $1`${@:2}" 5 + # reset color if there are arguments: 6 + if [[ "$#" > 1 ]]; then echo -n "`tput setaf 7`"; fi 7 + } 8 + red() { color 1 "$@"; } 9 + green() { color 2 "$@"; } 10 + cyan() { color 6 "$@"; } 11 + reset() { color 7 "$@"; echo -n `tput sgr0`; } 12 + 13 + aerender=/Applications/Adobe\ After\ Effects\ CC\ 2019/aerender 14 + 3 15 help() { 4 - SCRIPT_FILENAME=${0##*/} 5 - echo "" 6 - echo "`tput setaf 2`Usage:`tput setaf 7`" 7 - echo " `tput setaf 6`$SCRIPT_FILENAME`tput setaf 7` <path>" 8 - echo "" 9 - echo "`tput setaf 2`Options:`tput setaf 7`" 10 - echo " `tput setaf 6`path`tput setaf 7` After Effects .aep file for aerender to render." 11 - echo "" 16 + FILENAME=${0##*/} 17 + echo " 18 + `green Usage:` 19 + `cyan $FILENAME` <file> [file...] 20 + 21 + `green Options:` 22 + `cyan file` After Effects .aep file for After Effects' aerender to render. 23 + " 12 24 } 13 25 14 - render() { 15 - /Applications/Adobe\ After\ Effects\ CC\ 2019/aerender -project "$1" 16 - } 17 - if [[ $1 ]]; then 18 - ERRORS=() 19 - for ARG in "$@"; do 20 - echo "" 21 - if [[ -d "$ARG" ]]; then 22 - for FILE in "$ARG"/*; do 23 - if [[ -f "$FILE" && $FILE == */Project.aep ]]; then 24 - render "$FILE" 25 - fi 26 - done 27 - elif [[ -f "$ARG" && $ARG == *.aep ]]; then 28 - render "$ARG" 29 - else 30 - echo ERROR: Not a directory or .aep file: ${ARG} 31 - ERRORS+=($ARG) 32 - fi 33 - done 34 - echo "" 35 - if [[ ${#ERRORS[@]} != 0 ]]; then 36 - echo ERROR: One or more paths were not directories or .aep files: 37 - for ELEMENT in ${FILES[@]}; do 38 - echo File: $ELEMENT. 39 - done 26 + # no args 27 + if [[ "$#" < 1 ]]; then help; exit 0; fi 28 + 29 + # proactively check for errors 30 + for ARG in "$@"; do 31 + if [[ ! -f "$ARG" ]]; then 32 + echo "`red Error:` File does not exist: $ARG" 33 + ERRORS=true 34 + elif [[ "$ARG" != *.aep ]]; then 35 + echo "`red Error:` File must be .aep: $ARG" 36 + ERRORS=true 40 37 else 41 - echo "Done rendering" 38 + FILES+=() 42 39 fi 43 - 44 - else 45 - help 40 + done 41 + 42 + # exit if there were errors 43 + if [[ $ERRORS == true ]]; then exit 1; fi 44 + 45 + ERRORS=() 46 + err() { 47 + ERRORS+=("$1") 48 + echo `red ✖ Error:` "$1" 49 + } 50 + # render 51 + for ARG in "$@"; do 52 + if [[ ! -f "$ARG" ]]; then 53 + err "File does not exist: $ARG" 54 + elif [[ "$ARG" != *.aep ]]; then 55 + err "File must be .aep: $ARG" 56 + else 57 + echo "" 58 + FILE="$(cd "$(dirname "$ARG")" && pwd)/$(basename "$ARG")" # get absolute path 59 + command "$aerender" -project "$FILE" || err "Render failed: $ARG" 60 + fi 61 + done 62 + 63 + # recap errors 64 + # if more than one render 65 + if [[ "$#" > 1 && ${#FILES[@]} ]]; then 66 + # if errors 67 + if [[ ${#FILES[@]} == 0 ]]; then 68 + printf "\n\n\n" 69 + echo "`tput bold``red`Errors occured while rendering:`reset`" 70 + for ERROR in "$ERRORS"; do 71 + echo " `red ✖ Error:` $ERROR" 72 + done 73 + printf "\n\n\n" 74 + fi 46 75 fi