Skip to content

Instantly share code, notes, and snippets.

@nedveed
Forked from luukvbaal/cacheremove.hook
Last active September 3, 2019 12:51
Show Gist options
  • Save nedveed/fdf97b8a7062d7b6b4048f920ae0725f to your computer and use it in GitHub Desktop.
Save nedveed/fdf97b8a7062d7b6b4048f920ae0725f to your computer and use it in GitHub Desktop.
yay paccache hooks
[Trigger]
Operation = Upgrade
Type = Package
Target = *
[Action]
Description = Clearing old cache...
When = PostTransaction
Exec = <path_to_script>/pacman_yay_clean_cache.sh
#!/bin/sh
#
# Clean cache pacman & yay script
#
## TODO: Auto get pacman cachedir (can be changed)
# Idea: extract from pacman.conf?
PACMAN_CACHE_DIR=/var/cache/pacman/pkg
## TODO: Check if yay is installed(if no, skip),
# then check if yaycachedir is changed,
# if not, use default ~/.cache/yay
YAY_CACHE_DIR=/home/$USER/.cache/yay
# Unlike pacman, yay splits cache to dirs by pkg name
# add '-c' before path for paccache:
# -c, --cachedir <dir> scan "dir" for packages. can be used more than once.
cache_dirs="$(find $YAY_CACHE_DIR -maxdepth 1 -type d | awk '{ print "-c " $1 }' | tail -n +2)"
# add pacman cache dir
cache_dirs+=" -c $PACMAN_CACHE_DIR"
# clean
echo "==> Keep last 3 installed versions"
paccache -rk3 $cache_dirs
echo "==> Remove cache of uninstalled pkgs"
paccache -ruk0 $cache_dirs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment