From 22120b23374759004e7e07a944f5e71aa41b0884 Mon Sep 17 00:00:00 2001 From: "taha@ang-kemi197131" Date: Tue, 29 Sep 2020 14:37:38 +0200 Subject: [PATCH] assets.external now supports specifying target subdir I did this to lessen risk of filename clashes in the thesis/assets/data/ folder. This way, I can easily have a separate subdir for each manuscript. --- chertex.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/chertex.sh b/chertex.sh index 59d8725..99ef117 100755 --- a/chertex.sh +++ b/chertex.sh @@ -134,10 +134,33 @@ if [ $# -eq 1 ]; then # find all files named "assets.external" in the assets/ tree assetsexternalfiles=$(find "$path_wd/assets/" -type f -name "assets.external") for externalfilepath in $assetsexternalfiles; do - # this weird-looking while-loop reads the assets.external file line-by-line and copies each asset into the target path inside the thesis' assets/ tree # https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable while IFS='' read -r asset || [[ -n "$asset" ]]; do + # $asset contains one line from the current external.assets + # assetpathtarget is the directory of the current external.assets file assetpathtarget=$(dirname "$externalfilepath") + # if $asset contains a space, the second element should be considered a local target folder for the copy operation + # https://www.tutorialkart.com/bash-shell-scripting/bash-split-string/ + # https://stackoverflow.com/a/30212526 + IFS=' ' # reset IFS + # asset is read into an array as tokens separated by IFS + read -ra asset_array <<< "$asset" + # sanity check for array length + if [ ${#asset_array[@]} -gt 2 ]; then + echo " Cannot handle more than one space per line" + echo " Terminating..." + simpledelay.sh 2 + exit 1 + fi + if [ ${#asset_array[@]} -gt 1 ]; then + # echo "Placing this asset into subdirectory ${asset_array[1]}" + # redefine assetpathtarget to include the local subdir + assetpathtarget="$assetpathtarget/${asset_array[1]}" + # also redefine $asset so we keep only the asset path + asset="${asset_array[0]}" + # create the local subdir inside assets/ Copying $asset to $assetpathtarget" # cp but don't overwrite existing files cp --preserve=timestamps --no-clobber $asset $assetpathtarget