56 lines
1.6 KiB
Plaintext
56 lines
1.6 KiB
Plaintext
|
#!/bin/bash
|
||
|
# Cleans up files according to given parameters
|
||
|
|
||
|
typeset -A _clean_map
|
||
|
_clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp)
|
||
|
# Directories to always clean
|
||
|
_clean_folders=()
|
||
|
|
||
|
for f in $_clean_folders
|
||
|
do test -d $f && rm -rv $f
|
||
|
done
|
||
|
|
||
|
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
|
||
|
|
||
|
highlight "c to recursively remove development caches"
|
||
|
if [[ $1 =~ "c" ]]; then
|
||
|
find -name ".gradle" -o -name "generated" -o -name "dist_newstyle" -o -name "cache" -o -name "node_modules" -print -exec rm -r {} + -prune
|
||
|
find -name "*build" -print -exec rm -rI {} + -prune
|
||
|
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
|
||
|
|