From a6d113956cc38e3c8149c57b4adc38de460a88fa Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Fri, 30 Jun 2023 21:03:21 -0700 Subject: [PATCH] Functions min_jpg and min_png work on multiple files --- .../profile/profile.d/functions.sh.tmpl | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dot_config/profile/profile.d/functions.sh.tmpl b/dot_config/profile/profile.d/functions.sh.tmpl index 50e44bb..5af8c9e 100644 --- a/dot_config/profile/profile.d/functions.sh.tmpl +++ b/dot_config/profile/profile.d/functions.sh.tmpl @@ -95,19 +95,25 @@ command_installed() ( min_jpg() ( set -ue command_installed jpegtran - file=$1 - out_file=$(mktemp) - jpegtran -optimize -perfect -outfile "$out_file" "$file" - mv "$out_file" "$file" + for FILE in "$@" ; do + PERMISSIONS=$(stat --format '%a' "${FILE}") + OUT_FILE=$(mktemp) + jpegtran -optimize -perfect -outfile "${OUT_FILE}" "${FILE}" + mv "${OUT_FILE}" "${FILE}" + chmod "${PERMISSIONS}" "${FILE}" + done ) min_png() ( set -ue command_installed pngcrush - out_file=$(mktemp) - file=$1 - pngcrush -rem alla -reduce -brute "$file" "$out_file" - mv "$out_file" "$file" + for FILE in "$@" ; do + PERMISSIONS=$(stat --format '%a' "${FILE}") + OUT_FILE=$(mktemp) + pngcrush -rem alla -reduce -brute "${FILE}" "${OUT_FILE}" + mv "${OUT_FILE}" "${FILE}" + chmod "${PERMISSIONS}" "${FILE}" + done ) get_create_date() (