|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +source "$DOTLY_PATH/scripts/core/_main.sh" |
| 6 | + |
| 7 | +##? Empty the trash and remove cache files |
| 8 | +#?? 1.0.0 |
| 9 | +##? |
| 10 | +##? Usage: |
| 11 | +##? empty_trash |
| 12 | +docs::parse "$@" |
| 13 | + |
| 14 | +free_space_in_home() { |
| 15 | + df -h ~ | tail -n1 | awk '{print $4}' |
| 16 | +} |
| 17 | + |
| 18 | +free_space_before_empty=$(free_space_in_home) |
| 19 | + |
| 20 | +ls /Volumes | grep -v GoogleDrive | xargs -I_ sudo rm -rfv /Volumes/_/.Trashes |
| 21 | +sudo rm -rfv ~/.Trash/* |
| 22 | +echo '🗑 All trashes empty' |
| 23 | + |
| 24 | +sudo rm -rfv /private/var/log/asl/*.asl |
| 25 | +sudo rm -rfv /var/log/asl/*.asl |
| 26 | +echo '📜 Mac logs empty' |
| 27 | + |
| 28 | +sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent' |
| 29 | +echo '⏬ Mac downloads history empty' |
| 30 | + |
| 31 | +rm -rf "$HOME/Movies/"*.fcpbundle"/"*"/Render Files/High Quality Media" |
| 32 | +echo '🎬 Final Cut rendered media cleared' |
| 33 | + |
| 34 | +brew cleanup |
| 35 | +brew cleanup --prune-prefix |
| 36 | +rm -rf ~/Library/Caches/Homebrew |
| 37 | +echo '🍺 Brew cache cleared' |
| 38 | + |
| 39 | +rm -rf ~/Library/Caches/com.tinyspeck.slackmacgap |
| 40 | +rm -rf ~/Library/Caches/com.tinyspeck.slackmacgap.ShipIt |
| 41 | +rm -rf ~/Library/Application Support/Slack/Cache |
| 42 | +rm -rf "$HOME/Library/Application Support/Slack/Service Worker/CacheStorage" |
| 43 | +echo '💬 Slack cache cleared' |
| 44 | + |
| 45 | +rm -rf ~/Library/Caches/com.spotify.client/Data |
| 46 | +echo '🎶 Spotify cache cleared' |
| 47 | + |
| 48 | +rm -rf ~/Library/Caches/JetBrains |
| 49 | +echo '🅸 JetBrains cache cleared' |
| 50 | + |
| 51 | +rm -rf ~/Library/Caches/Yarn/ |
| 52 | +echo '💪 Yarn cache cleared' |
| 53 | + |
| 54 | +rm -rf ~/.gradle/wrapper/dists/ |
| 55 | +rm -rf ~/.gradle/caches/ |
| 56 | +echo '🐘 Gradle cache cleared' |
| 57 | + |
| 58 | +rm -rf ~/.composer/cache/ |
| 59 | +echo '👨🎤 Composer cache cleared' |
| 60 | + |
| 61 | +rm -rf ~/Library/Caches/Google/Chrome || true |
| 62 | +rm -rf "$HOME/Library/Application Support/Google/Chrome/"*"/Service Worker/CacheStorage" || true |
| 63 | +rm -rf "$HOME/Library/Application Support/Google/Chrome/"*"/Application Cache/Cache" || true |
| 64 | +echo '🟡 Chrome cache cleared' |
| 65 | + |
| 66 | +free_space_after_empty=$(free_space_in_home) |
| 67 | + |
| 68 | +echo "Done! Free space before: $free_space_before_empty, free space now: $free_space_after_empty" |
0 commit comments