2021-09-18 21:04:50 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Cleans up files according to given parameters
|
|
|
|
|
|
|
|
typeset -A _clean_map
|
2021-11-04 11:24:23 +00:00
|
|
|
_clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp [l]=/var/log [c]=/var/cache)
|
2021-09-18 21:04:50 +00:00
|
|
|
# Directories to always clean
|
2021-11-10 16:42:28 +00:00
|
|
|
_clean_folders=(~/.ant ~/.autopsy ~/.bundle ~/.cache ~/.cargo ~/.cpanm ~/.docker ~/.electron ~/.electron-gyp ~/.gradle ~/.gradle-kotlin-dsl ~/.hex ~/.java ~/.kscript ~/.konan ~/.m2 ~/.mix ~/.nix-defexpr ~/.node-gyp ~/.npm ~/.nv ~/.openjfx ~/.parallel ~/.stack ~/.surf ~/.texlive ~/.yarn luametatex-cache
|
2021-11-09 04:37:07 +00:00
|
|
|
~/.lesshst ~/.rubberband.wisdom.d ~/.yarnrc)
|
2021-09-18 21:04:50 +00:00
|
|
|
|
2021-11-04 11:24:23 +00:00
|
|
|
|
|
|
|
for f in ${_clean_folders[@]}
|
|
|
|
do test -f $f || test -d $f && highlight $f && rm -rf $f
|
2021-09-18 21:04:50 +00:00
|
|
|
done
|
2021-11-04 11:24:23 +00:00
|
|
|
find $HOME -maxdepth 2 -not -name ".stfolder" -type d -empty -exec rm -vd {} +
|
2021-09-18 21:04:50 +00:00
|
|
|
|
|
|
|
highlight "g to clean gradle"
|
|
|
|
if [[ $1 =~ "g" ]]; then
|
|
|
|
find ${GRADLE_USER_HOME:-$HOME/.gradle} -mindepth 1 -maxdepth 1 -type d -print -exec rm -r {} +
|
|
|
|
find $projects_dir -name .gradle -print -exec rm -r {} +
|
|
|
|
fi
|
|
|
|
|
|
|
|
highlight "e to clean electron caches"
|
|
|
|
[[ $1 =~ "e" ]] && find "$XDG_CONFIG_HOME" -type d -name "*Cache" -exec rm -r {} + -prune
|
|
|
|
|
|
|
|
for k in "${!_clean_map[@]}"; do
|
|
|
|
folder="${_clean_map[$k]}"
|
|
|
|
highlight "$k to delete $folder"
|
|
|
|
[[ $1 =~ "$k" ]] && sudo rm -rf "$folder" && echo "Deleted $folder"
|
|
|
|
done
|
|
|
|
|
|
|
|
if test -f "/var/log/apt/history.log"; then
|
|
|
|
aptclean_cur=$(cat "/var/log/apt/history.log" | wc -l)
|
|
|
|
test "$aptclean_cur" -gt "$aptclean_last" && aptclean && echo "Cleaned apt"
|
|
|
|
export aptclean_last=$aptclean_cur
|
|
|
|
fi
|
|
|
|
|
2021-09-29 16:38:57 +00:00
|
|
|
highlight "d to recursively remove development caches"
|
|
|
|
if [[ $1 =~ "d" ]]; then
|
2021-10-27 08:00:54 +00:00
|
|
|
rm -rf .npm .yarn
|
2021-09-29 16:38:57 +00:00
|
|
|
find -name "src" -prune -o \
|
2021-09-29 16:58:41 +00:00
|
|
|
-type d \( -name ".gradle" -o -name "generated" -o -name "dist-newstyle" -o -name "cache" -o -name "node_modules" -o -name "cmake_build" \) \
|
2021-09-29 16:38:57 +00:00
|
|
|
-print -exec rm -r {} + -prune
|
|
|
|
echo -n " " && highlight "build directories"
|
2021-11-10 16:42:28 +00:00
|
|
|
find $DATA/2-standards/dev/aur -mindepth 2 -maxdepth 2 -type d -not -name ".*" \
|
|
|
|
-print -exec sudo rm -rI {} +
|
|
|
|
find \( -name ".git" -o -path "*/mixxx/build" -o -name "Leaflet" -o -name "www" -o -name "src" \) \
|
|
|
|
-prune -o -name "build" -type d \
|
2021-09-29 16:38:57 +00:00
|
|
|
-print -exec rm -rI {} + -prune
|
2021-09-18 21:04:50 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
highlight "m to recursively remove mac-files"
|
|
|
|
if [[ $1 =~ "m" ]]; then
|
|
|
|
find -iname '.spotlight*' -exec rm -rI {} +
|
|
|
|
find -name '*.DS_Store' -delete
|
|
|
|
fi
|
|
|
|
|
|
|
|
highlight "f to recursively remove empty folders"
|
|
|
|
[[ $1 =~ "f" ]] && find -empty -type d -delete -print
|
|
|
|
|
|
|
|
highlight "o to optimize space extensively"
|
|
|
|
if [[ $1 =~ "o" ]]; then
|
|
|
|
which yay &>/dev/null && yay -Sc --noconfirm
|
|
|
|
nix-collect-garbage -d
|
|
|
|
nix-store --optimize
|
|
|
|
fi
|
|
|
|
|