-
Notifications
You must be signed in to change notification settings - Fork 8
/
cleanup
executable file
·88 lines (58 loc) · 1.69 KB
/
cleanup
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# macos-scripts/cleanup
# cleanup
# Purge some caches and take out the trash
set -euo pipefail
# -e exit if any command returns non-zero status code
# -u prevent using undefined variables
# -o pipefail force pipelines to fail on first non-zero status code
IFS=$'\n\t'
# Set Internal Field Separator to newlines and tabs
# This makes bash consider newlines and tabs as separating words
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
### UTILITY FUNCTIONS ###
# check_developer_tools
function check_developer_tools {
if ! xcode-select -p >/dev/null 2>&1; then
echo "[❌] Command line developer tools required"
echo "[🍺] Install via: xcode-select --install"
exit 1
fi
}
### END UTILITY FUNCTIONS ###
function clean_xcode {
# Delete old iOS simulators
if check_developer_tools; then
echo "[🗑] Deleting old Xcode iOS Simulators"
xcrun simctl delete unavailable
fi
}
function clean_brew {
# Remove outdated downloads for formulae and casks,
# and remove old versions of installed formulae.
# Scrub the cache of the latest versions
if [ -x "$(command -v brew)" ]; then
echo "[🗑] Cleaning Brew"
brew cleanup -s
# Remove cache for installed formula and cask
rm -rf "$(brew --cache)"
fi
}
function clean_ruby {
# Remove old versions of gems
# that are not required to meet a dependency.
if [ -x "/usr/local/opt/ruby/bin/gem" ]; then
echo "[🗑] Cleaning Ruby Gems"
/usr/local/opt/ruby/bin/gem cleanup >/dev/null 2>&1
fi
}
function empty_trash {
echo "[🗑] Emptying Trash"
rm -rf "${HOME:?}/.Trash/"*
}
function main {
clean_brew
clean_ruby
empty_trash
}
main "$@"