Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@Morganamilo

This comment has been minimized.

Copy link

@Morganamilo Morganamilo commented May 28, 2019

yaycache="$(yay -Pg | jq .buildDir)" ;)

@luukvbaal

This comment has been minimized.

Copy link
Owner Author

@luukvbaal luukvbaal commented May 28, 2019

Unfortunately paccache doesn't work recursively as far as I know hence why I pass all sub-folders in yay buildDir.
But I guess the hard-coded directory could be replaced by $(yay -Pg | jq -r .buildDir) if you want, e.g. yaycache="$(find $(yay -Pg | jq -r .buildDir) -maxdepth 1 -type d | awk '{ print "-c " $1 }' | tail -n +2)"

@Morganamilo

This comment has been minimized.

Copy link

@Morganamilo Morganamilo commented May 28, 2019

Honestly the better option is to just set PKGDIR and have paccache clean that.

@luukvbaal

This comment has been minimized.

Copy link
Owner Author

@luukvbaal luukvbaal commented May 28, 2019

Yes I guess it is, thanks.

@GavinTao1219

This comment has been minimized.

Copy link

@GavinTao1219 GavinTao1219 commented Oct 16, 2021

These hooks are great! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment