From f1b57f97ef4439fa3c9dcb9e7633bf8ff1e7de99 Mon Sep 17 00:00:00 2001 From: Edwin Date: Tue, 2 Apr 2024 08:23:15 +0200 Subject: [PATCH] Update functions.sh Introducing wildcards for files. Used for example in pycharm --- fragments/functions.sh | 58 +++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/fragments/functions.sh b/fragments/functions.sh index 39c446d..cac9983 100644 --- a/fragments/functions.sh +++ b/fragments/functions.sh @@ -35,33 +35,39 @@ quitApp() { fi } -removeFileDirectory() { # $1: object $2: logmode - object=${1:-"Object"} - logmode=${2:-"Log Mode"} - if [ -f "$object" ]; then - # file exists and can be removed - printlog "Removing file $object" - if [ "$DEBUG" -eq 0 ]; then - /bin/rm -f "$object" - fi - elif [ -d "$object" ]; then - # it is not a file, it is a directory and can be removed - printlog "Removing directory $object..." - if [ "$DEBUG" -eq 0 ]; then - /bin/rm -Rf "$object" - fi - elif [ -L "$object" ]; then - # it is an alias - printlog "Removing alias $object..." - if [ "$DEBUG" -eq 0 ]; then - /bin/rm -f "$object" - fi - else - # it is not a file, alias or a directory. Don't remove. - if [ "$logmode" != "silent" ]; then - printlog "INFO: $object is not an existing file or folder" +removeFileDirectory() { # $1: objects $2: logmode + objects=${1:-"Object"} + logmode=${2:-"Log Mode"} + objects=${objects// /\\ } # objects are one or more because of wildcard(s) + objects=$(eval find $objects -depth 0) + for object in ${(f)objects} + do + object=${object//\"//} + if [ -f "$object" ]; then + # file exists and can be removed + printlog "Removing file $object" + if [ "$DEBUG" -eq 0 ]; then + /bin/rm -f "$object" + fi + elif [ -d "$object" ]; then + # it is not a file, it is a directory and can be removed + printlog "Removing directory $object..." + if [ "$DEBUG" -eq 0 ]; then + /bin/rm -Rf "$object" + fi + elif [ -L "$object" ]; then + # it is an alias + printlog "Removing alias $object..." + if [ "$DEBUG" -eq 0 ]; then + /bin/rm -f "$object" + fi + else + # it is not a file, alias or a directory. Don't remove. + if [ "$logmode" != "silent" ]; then + printlog "INFO: $object is not an existing file or folder" + fi fi - fi + done } removeLaunchDaemons() {