forked from Blackjacx/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean-mac.sh
executable file
·59 lines (47 loc) · 1.53 KB
/
clean-mac.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
echo "Clean up unused gem versions..."
gem cleanup
echo "Erase DerivedData folder..."
rm -rf ${HOME}/Library/Developer/Xcode/DerivedData/*
echo "Erase Caches Folder..."
rm -rf ${HOME}/Library/Caches
echo "Reset all simulators..."
osascript -e 'tell application "Simulator" to quit'
osascript -e 'tell application "iOS Simulator" to quit'
xcrun simctl shutdown all
xcrun simctl erase all
echo "Delete unneeded simulator devices..."
xcrun simctl delete unavailable
echo "Empty Trash..."
rm -rf ~/.Trash/*
echo "Create huge file and delete it again to re-claim hidden space from the system."
fname="DELETE_THIS_DUMMY_FILE_TO_FREE_UP_SPACE.txt"
pwd=$(pwd)
cd /tmp/
mkfile 13G $fname
rm -rf $fname
cd $pwd
# ##
# ## The following is highly experimental!!!
# ## It is used to automatically delete iOS device support files and keeps
# ## the two most recent versions. Those are one of the biggest space
# ## killers in iOS world.
# ##
# # set -euo pipefail
# # 1: find all versions (folders) currently installed
# # 2: reverse sort folders - use file name major version as key
# folders=$(find ${HOME}/Library/Developer/Xcode/iOS\ DeviceSupport -type d -d 1 \
# | sort -t. -nr)
# # 1: filter latest 2 major versions
# # 2: remove path components after the version number
# # 3: trim trailing whitespaces
# keep=$(echo "${folders[*]}" \
# | awk -F. 'a[$1]++<1' \
# | cut -d'(' -f1 \
# | sed 's/ *$//g' \
# | head -2 \
# | paste -s -d '|' -)
# # echo "${folders[*]}" | grep -vE $keep
# echo "${folders[*]}"
# echo "-----"
# echo "${keep}"