From 370ee7d9c1e4e1f40ca521292517d89f89da6499 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Sun, 31 Mar 2019 17:56:38 -0400 Subject: [PATCH] tasty solution to spacemall weirdness just dropped the really problematic approach using find with multiple match inames, instead opting for simpler streaming processing of the names into xargs. works beautifully. --- scripts/core/functions.sh | 15 +++++++++------ scripts/files/spacem.sh | 9 --------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index 5faa407d..109c72f8 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -926,15 +926,18 @@ return 0 # in the directories specified. function spacemall() { local -a dirs=("${@}") -echo "dirs from params are: " "${dirs[@]}" if [ ${#dirs[@]} -eq 0 ]; then -echo dirs had zero entries dirs=(.) fi -echo "dirs are now: " "${dirs[@]}" - local ext_list="$(echo pdf png jpg jpeg odt ods docx m4a mp3 eml html mov pptx xlsx zip | sed -e 's/\([a-z0-9][a-z0-9]*\)/-iname \"*.\1\" -o /g')" -echo "ext_list=$ext_list" - find "${dirs[@]}" -follow -maxdepth 1 -mindepth 1 -type f $ext_list -iname "*.txt" -exec bash "$FEISTY_MEOW_SCRIPTS/files/spacem.sh" "{}" \; + + local charnfile="$(mktemp $TMP/zz_charn.XXXXXX)" + find "${dirs[@]}" -follow -maxdepth 1 -mindepth 1 -type f | \ + grep \ +"docx\|eml\|html\|jpeg\|jpg\|m4a\|mov\|mp3\|ods\|odt\|pdf\|png\|pptx\|txt\|xlsx\|zip" | \ + sed -e 's/^/"/' | sed -e 's/$/"/' | \ + xargs bash "$FEISTY_MEOW_SCRIPTS/files/spacem.sh" + # drop the temp file now that we're done. + rm "$charnfile" } ############## diff --git a/scripts/files/spacem.sh b/scripts/files/spacem.sh index 9b201c5c..b73a68c5 100644 --- a/scripts/files/spacem.sh +++ b/scripts/files/spacem.sh @@ -4,7 +4,6 @@ function spacem_out() { while [ $# -gt 0 ]; do arg="$1"; shift -echo "arg is '$arg'" if [ ! -f "$arg" -a ! -d "$arg" ]; then echo "=> did not find a file or directory named '$arg'." continue @@ -16,7 +15,6 @@ echo "arg is '$arg'" intermediate_name="$(bash "$FEISTY_MEOW_SCRIPTS/files/replace_spaces_with_underscores.sh" "$arg")" local saw_intermediate_result=0 if [ -z "$intermediate_name" ]; then -echo no new intermed name reported # make sure we report something, if there are no further name changes. intermediate_name="'$arg'" else @@ -27,20 +25,14 @@ echo no new intermed name reported # here we rename the file to be lower case. actual_file="$(echo $intermediate_name | sed -e "s/'\([^']*\)'/\1/")" -echo actual file computed: $actual_file final_name="$(perl "$FEISTY_MEOW_SCRIPTS/files/renlower.pl" "$actual_file")" local saw_final_result=0 -echo temp final name is: $final_name if [ -z "$final_name" ]; then final_name="$intermediate_name" else final_name="$(echo $final_name | sed -e 's/.*=> //' )" saw_final_result=1 fi -echo intermed result=$saw_intermediate_result -echo intermed name=$intermediate_name -echo final result=$saw_final_result -echo final name=$final_name if [[ $saw_intermediate_result != 0 || $saw_final_result != 0 ]]; then # printout the combined operation results. @@ -52,7 +44,6 @@ echo final name=$final_name # this block should execute when the script is actually run, rather # than when it is just being sourced. if [[ $0 =~ .*spacem\.sh.* ]]; then -echo inside exec block for spacem source "$FEISTY_MEOW_SCRIPTS/core/launch_feisty_meow.sh" exit_on_error "sourcing the feisty meow environment" spacem_out "${@}" -- 2.34.1