Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update functions.sh (using wildcards) #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions fragments/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down