Skip to content

Instantly share code, notes, and snippets.

@MatthewRalston
Forked from luukvbaal/cacheremove.hook
Created January 23, 2021 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewRalston/c48922ca87aa73092a2adf459cbb5006 to your computer and use it in GitHub Desktop.
Save MatthewRalston/c48922ca87aa73092a2adf459cbb5006 to your computer and use it in GitHub Desktop.
yay paccache hooks
[Trigger]
Operation = Remove
Type = Package
Target = *
[Action]
Description = Clearing cache...
When = PostTransaction
Exec = /home/<user>/.local/bin/tools/removehook
[Trigger]
Operation = Upgrade
Type = Package
Target = *
[Action]
Description = Clearing cache...
When = PostTransaction
Exec = /home/<user>/.local/bin/tools/upgradehook
#!/bin/sh
yaycache="$(find /home/<user>/.cache/yay -maxdepth 1 -type d | awk '{ print "-c " $1 }' | tail -n +2)"
yayremoved=$(/usr/bin/paccache -ruvk0 $yaycache | sed '/\.cache\/yay/!d' | cut -d \' -f2 | rev | cut -d / -f2- | rev)
[ -z $yayremoved ] || echo "==> Remove all uninstalled package folders" &&
echo $yayremoved | xargs -rt rm -r
#!/bin/sh
yaycache="$(find /home/<user>/.cache/yay -maxdepth 1 -type d | awk '{ print "-c " $1 }' | tail -n +2)"
echo "==> Keep last 2 installed versions"
/usr/bin/paccache -rvk2 -c /var/cache/pacman/pkg $yaycache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment