First Commit
This commit is contained in:
255
Clear.sh
Executable file
255
Clear.sh
Executable file
@@ -0,0 +1,255 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
Version="1.0"
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
# Reset
|
||||||
|
Color_Off='\033[0m' # Text Reset
|
||||||
|
|
||||||
|
# Regular Colors
|
||||||
|
Black='\033[0;30m' # Black
|
||||||
|
Red='\033[0;31m' # Red
|
||||||
|
Green='\033[0;32m' # Green
|
||||||
|
Yellow='\033[0;33m' # Yellow
|
||||||
|
Blue='\033[0;34m' # Blue
|
||||||
|
Purple='\033[0;35m' # Purple
|
||||||
|
Cyan='\033[0;36m' # Cyan
|
||||||
|
White='\033[0;37m' # White
|
||||||
|
|
||||||
|
# Bold
|
||||||
|
BBlack='\033[1;30m' # Black
|
||||||
|
BRed='\033[1;31m' # Red
|
||||||
|
BGreen='\033[1;32m' # Green
|
||||||
|
BYellow='\033[1;33m' # Yellow
|
||||||
|
BBlue='\033[1;34m' # Blue
|
||||||
|
BPurple='\033[1;35m' # Purple
|
||||||
|
BCyan='\033[1;36m' # Cyan
|
||||||
|
BWhite='\033[1;37m' # White
|
||||||
|
|
||||||
|
ProgNameColor=$BYellow
|
||||||
|
AuthorNameColor=$BGreen
|
||||||
|
VersionColor=$BBlue
|
||||||
|
BarColor=$Cyan
|
||||||
|
FoundColor=$Blue
|
||||||
|
SizeColor=$Green
|
||||||
|
ClearableNameColor=$Yellow
|
||||||
|
NotFoundColor=$Purple
|
||||||
|
ResultSizeColor=$Green
|
||||||
|
|
||||||
|
FoundText="${FoundColor}Found !${Color_Off}"
|
||||||
|
|
||||||
|
# Sudo function
|
||||||
|
asksudo() {
|
||||||
|
echo "Checking for sudo permissions..."
|
||||||
|
if [[ "$EUID" = 0 ]]; then
|
||||||
|
echo "${Green}Already have sudo !${Color_Off}"
|
||||||
|
else
|
||||||
|
sudo -k
|
||||||
|
if sudo true; then
|
||||||
|
echo "${Green}Correct password !${Color_Off}"
|
||||||
|
else
|
||||||
|
echo "${Red}Wrong password.${Color_Off}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# -- Clearing functions -- #
|
||||||
|
coreSimClear() {
|
||||||
|
CoreSimCaches="${HOME}/Library/Developer/CoreSimulator/Caches"
|
||||||
|
|
||||||
|
echo "${BarColor}====== ${ClearableNameColor}CoreSimulator ${BarColor}======${Color_Off}"
|
||||||
|
echo "Checking for ${ClearableNameColor}CoreSimulator${Color_Off}'s cache folder..."
|
||||||
|
|
||||||
|
#if [[ -d "$CoreSimCaches" ]]
|
||||||
|
if [ -n "$(ls -d ${CoreSimCaches}/* 2>/dev/null)" ];
|
||||||
|
then
|
||||||
|
echo "${FoundText}"
|
||||||
|
|
||||||
|
echo "Deleting ${ClearableNameColor}CoreSimulator${Color_Off}'s cache... ${SizeColor}($(du -sh ${CoreSimCaches} | cut -f1))${Color_Off}"
|
||||||
|
cleared=$(($cleared+$(du -sk ${CoreSimCaches} | cut -f1)))
|
||||||
|
sudo rm -rv ${CoreSimCaches}/* | pv -l -s $(du -a ${CoreSimCaches} | wc -l)> /dev/null
|
||||||
|
else
|
||||||
|
echo "${ClearableNameColor}CoreSimulator${Color_Off}'s cache ${NotFoundColor}not found${Color_Off}."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
gradleJavaClear() {
|
||||||
|
GradleJarFiles="${HOME}/.gradle/caches"
|
||||||
|
|
||||||
|
echo "${BarColor}====== ${ClearableNameColor}Gradle ${BarColor}======${Color_Off}"
|
||||||
|
echo "Checking for ${ClearableNameColor}gradle${Color_Off} java cache folders..."
|
||||||
|
|
||||||
|
if [ -n "$(ls -d ${GradleJarFiles}/jars-* 2>/dev/null)" ];
|
||||||
|
then
|
||||||
|
echo "${FoundText}"
|
||||||
|
|
||||||
|
echo "Clearing ${ClearableNameColor}Gradle${Color_Off} java caches... ${SizeColor}($(du -sch ${GradleJarFiles}/jars-* | grep 'total' | cut -f1))${Color_Off}"
|
||||||
|
cleared=$(($cleared+$(du -sck ${GradleJarFiles}/jars-* | grep 'total' | cut -f1)))
|
||||||
|
sudo rm -rv ${GradleJarFiles}/jars-* | pv -l -s $(du -a ${GradleJarFiles}/jars-* | wc -l)> /dev/null
|
||||||
|
else
|
||||||
|
echo "${ClearableNameColor}Gradle${Color_Off} java cache folders ${NotFoundColor}not found${Color_Off}."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# The path has a space and I haven't found a way to pass it as an argument
|
||||||
|
discordClear() {
|
||||||
|
DiscordCache="${HOME}/Library/Application Support/discord/Cache"
|
||||||
|
|
||||||
|
echo "${BarColor}====== ${ClearableNameColor}Discord ${BarColor}======${Color_Off}"
|
||||||
|
echo "Checking for ${ClearableNameColor}Discord${Color_Off}'s cache folder..."
|
||||||
|
|
||||||
|
#if [[ -d "$DiscordCache" ]]
|
||||||
|
if [ -n "$(ls -d ${DiscordCache}/* 2>/dev/null)" ];
|
||||||
|
then
|
||||||
|
echo "${FoundText}"
|
||||||
|
|
||||||
|
echo "Clearing ${ClearableNameColor}Discord${Color_Off}'s cache... ${SizeColor}($(du -sh "$DiscordCache" | cut -f1))${Color_Off}"
|
||||||
|
cleared=$(($cleared+$(du -sk "$DiscordCache" | cut -f1)))
|
||||||
|
sudo rm -rv "$DiscordCache"/* | pv -l -s $(du -a "$DiscordCache" | wc -l)> /dev/null
|
||||||
|
else
|
||||||
|
echo "${ClearableNameColor}Discord${Color_Off}'s cache ${NotFoundColor}not found${Color_Off}."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
###################################################
|
||||||
|
|
||||||
|
## Clean out older Fusion 360 installations
|
||||||
|
|
||||||
|
###################################################
|
||||||
|
|
||||||
|
function deleteOldestInstallFusion360 () {
|
||||||
|
echo "${BarColor}====== ${ClearableNameColor}Clearing outdated Fusion360 versions ${BarColor}======${Color_Off}"
|
||||||
|
|
||||||
|
local targetDirectory="${HOME}/Library/Application Support/Autodesk/webdeploy/production"
|
||||||
|
|
||||||
|
if [[ -d "$targetDirectory" ]]
|
||||||
|
then
|
||||||
|
local linkToFind="$(readlink ${HOME}/Library/Application\ Support/Autodesk/webdeploy/production/Autodesk\ Fusion\ 360.app)"
|
||||||
|
local extractedFolderName="$(basename "$(dirname "$linkToFind")")"
|
||||||
|
|
||||||
|
echo "Target Directory is '""$targetDirectory""'"
|
||||||
|
echo "Currently used Fusion360 folder: ${extractedFolderName}"
|
||||||
|
|
||||||
|
if [ "$extractedFolderName" == "" ] || [ "$extractedFolderName" == "." ];
|
||||||
|
then
|
||||||
|
echo "${NotFoundColor}Unable to find the right folder${Color_Off}"
|
||||||
|
else
|
||||||
|
if [ "$linkToFind" == "" ];
|
||||||
|
then
|
||||||
|
echo "${NotFoundColor}Unable to find the right folder${Color_Off}"
|
||||||
|
else
|
||||||
|
local toDelete=0
|
||||||
|
# Calculating the size of files to delete with an overly complex command
|
||||||
|
toDelete=$(($toDelete$(find "$targetDirectory" -mindepth 1 -maxdepth 1 ! -name "$extractedFolderName" ! -name "Autodesk Fusion 360.app" ! -name ".DS_Store" -exec bash -c 'echo -n "+$(du -sk "$0" | cut -f1)"' "{}" \; )))
|
||||||
|
|
||||||
|
echo "Deleting folders... ${SizeColor}($(($toDelete/1024))M)${Color_Off}"
|
||||||
|
|
||||||
|
# Updating cleared
|
||||||
|
cleared=$(($cleared+$toDelete))
|
||||||
|
|
||||||
|
# Clearing folders w/ progression
|
||||||
|
find "$targetDirectory" -mindepth 1 -maxdepth 1 ! -name "$extractedFolderName" ! -name "Autodesk Fusion 360.app" ! -name ".DS_Store" -exec sh -c 'sudo rm -rv "$0" | pv -l -s $(du -a "$0" | wc -l)> /dev/null' "{}" \;
|
||||||
|
|
||||||
|
echo "Done!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "${ClearableNameColor}Fusion360${Color_Off}'s folder ${NotFoundColor}not found${Color_Off}."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#clearKeepFolder() {
|
||||||
|
# # Evals to workaround spaces in arguments
|
||||||
|
# eval folderPath="$2"
|
||||||
|
# eval clearableName="$1"
|
||||||
|
|
||||||
|
# echo "${BarColor}====== ${ClearableNameColor}${clearableName} ${BarColor}======${Color_Off}"
|
||||||
|
# echo "Checking for ${ClearableNameColor}${clearableName}${Color_Off}'s cache folder..."
|
||||||
|
|
||||||
|
# if [ -n "$(ls -d ${folderPath}/* 2>/dev/null)" ];
|
||||||
|
# then
|
||||||
|
# echo "${FoundText}"
|
||||||
|
|
||||||
|
# echo "Clearing ${ClearableNameColor}${clearableName}${Color_Off}'s cache... ${SizeColor}($(du -sh ${folderPath} | cut -f1))${Color_Off}"
|
||||||
|
# echo ${folderPath}
|
||||||
|
# cleared=$(($cleared+$(du -sk ${folderPath} | cut -f1)))
|
||||||
|
|
||||||
|
# sudo rm -rvi ${folderPath}/* | pv -l -s $(du -a ${folderPath} | wc -l)> /dev/null
|
||||||
|
# else
|
||||||
|
# echo "${ClearableNameColor}${clearableName}${Color_Off}'s cache ${NotFoundColor}not found${Color_Off}."
|
||||||
|
# fi
|
||||||
|
#}
|
||||||
|
|
||||||
|
clearFolder() {
|
||||||
|
# Evals to workaround spaces in arguments
|
||||||
|
eval folderPath="$2"
|
||||||
|
eval clearableName="$1"
|
||||||
|
|
||||||
|
echo "${BarColor}====== ${ClearableNameColor}${clearableName} ${BarColor}======${Color_Off}"
|
||||||
|
echo "Checking for ${ClearableNameColor}${clearableName}${Color_Off}'s cache folder..."
|
||||||
|
|
||||||
|
if [[ -d "$folderPath" ]]
|
||||||
|
then
|
||||||
|
echo "${FoundText}"
|
||||||
|
|
||||||
|
echo "Clearing ${ClearableNameColor}${clearableName}${Color_Off}'s cache... ${SizeColor}($(du -sh ${folderPath} | cut -f1))${Color_Off}"
|
||||||
|
echo "${folderPath}"
|
||||||
|
cleared=$(($cleared+$(du -sk ${folderPath} | cut -f1)))
|
||||||
|
sudo rm -rv "${folderPath}" | pv -l -s $(du -a ${folderPath} | wc -l)> /dev/null
|
||||||
|
else
|
||||||
|
echo "${ClearableNameColor}${clearableName}${Color_Off}'s cache ${NotFoundColor}not found${Color_Off}."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# ------------------------ #
|
||||||
|
|
||||||
|
# -- Main Script -- #
|
||||||
|
|
||||||
|
echo "${BarColor}==========================================${Color_Off}"
|
||||||
|
echo " Script ${ProgNameColor}Clear.sh${Color_Off} by ${AuthorNameColor}Skydust "
|
||||||
|
echo " ${VersionColor}v${Version}${Color_Off} "
|
||||||
|
echo "${BarColor}==========================================${Color_Off}"
|
||||||
|
|
||||||
|
# Setting size variable to 0
|
||||||
|
cleared=0
|
||||||
|
|
||||||
|
# Elevate permissions...
|
||||||
|
asksudo
|
||||||
|
|
||||||
|
# Clearing...
|
||||||
|
coreSimClear
|
||||||
|
|
||||||
|
gradleJavaClear
|
||||||
|
|
||||||
|
FirefoxCache="${HOME}/Library/Caches/Firefox"
|
||||||
|
clearFolder "Firefox" "${FirefoxCache}"
|
||||||
|
|
||||||
|
ThunderbirdCache="${HOME}/Library/Caches/Thunderbird"
|
||||||
|
clearFolder "Thunderbird" "${ThunderbirdCache}"
|
||||||
|
|
||||||
|
discordClear
|
||||||
|
#DiscordCache=$HOME"/Library/Application Support/discord/Cache"
|
||||||
|
#clearKeepFolder "Discord" "$DiscordCache"
|
||||||
|
|
||||||
|
HomebrewCache="${HOME}/Library/Caches/Homebrew"
|
||||||
|
clearFolder "Homebrew" "${HomebrewCache}"
|
||||||
|
|
||||||
|
JetbrainsCache="${HOME}/Library/Caches/JetBrains"
|
||||||
|
clearFolder "JetBrains" "${JetbrainsCache}"
|
||||||
|
|
||||||
|
VisualStudioInstallerCache="${HOME}/Library/Caches/VisualStudioInstaller"
|
||||||
|
clearFolder "VisualStudioInstaller" "${VisualStudioInstallerCache}"
|
||||||
|
|
||||||
|
VisualStudioCache="${HOME}/Library/Caches/VisualStudio"
|
||||||
|
clearFolder "VisualStudio" "${VisualStudioCache}"
|
||||||
|
|
||||||
|
Adobe="${HOME}/Library/Caches/Adobe"
|
||||||
|
clearFolder "Adobe" "${Adobe}"
|
||||||
|
|
||||||
|
deleteOldestInstallFusion360
|
||||||
|
|
||||||
|
|
||||||
|
# Print final
|
||||||
|
echo "${BarColor}==========================================${Color_Off}"
|
||||||
|
echo "Cleared ${ResultSizeColor}$(($cleared/1024))M${Color_Off} !"
|
||||||
|
echo "${BarColor}==========================================${Color_Off}"
|
||||||
20
README.md
20
README.md
@@ -1,3 +1,21 @@
|
|||||||
# MacOS-Clear-script
|
# MacOS-Clear-script
|
||||||
|
|
||||||
Simple bash script to clear stuff on MacOS
|
I made a simple script to clear the folders that regularly get enormous under MacOS.
|
||||||
|
|
||||||
|
The current version clears:
|
||||||
|
|
||||||
|
- Homebrew's cache
|
||||||
|
- Firefox's cache
|
||||||
|
- Thunderbird's cache
|
||||||
|
- CoreSimulator's cache (Xcode)
|
||||||
|
- Java Gradle caches
|
||||||
|
- Discord's cache
|
||||||
|
- Jetbrains's cache
|
||||||
|
- Old Fusion360 versions
|
||||||
|
- VisualStudio's cache
|
||||||
|
- VisualStudioInstaller's cache
|
||||||
|
- Adobe's cache (All apps)
|
||||||
|
|
||||||
|
The scripts requires sudo, so be careful with it.
|
||||||
|
|
||||||
|
I'm not responsible for any misusage or any problems that might arise from using this script.
|
||||||
|
|||||||
Reference in New Issue
Block a user