Skip to content

Instantly share code, notes, and snippets.

@tyjak
Last active December 12, 2023 20:13
Show Gist options
  • Save tyjak/8bfc3cd340d443b6847ccd443b4a1acc to your computer and use it in GitHub Desktop.
Save tyjak/8bfc3cd340d443b6847ccd443b4a1acc to your computer and use it in GitHub Desktop.
#!/bin/sh
# GistID: 8bfc3cd340d443b6847ccd443b4a1acc
yaycachedir=~/.cache/yay
yaycache="$(find $yaycachedir -maxdepth 1 -type d | awk '{ print "-c " $1 }' | tail -n +2)"
echo "==> Keep last 2 installed versions"
/usr/bin/paccache -rvk2 $yaycache
for pkgdir in "$yaycachedir"/*/; do
pkgname=$(basename "$pkgdir")
## find package with binary download and keep last two one
#if [[ "$pkgname" =~ ^.*-bin$ ]]; then
cd "$pkgdir"
filetodel=($(find $pkgdir -maxdepth 1 -regex '.*.\(gz\|zip\|deb\|AppImage\|pacman\)' -exec ls -1t "{}" + | tail +3))
for f in ${filetodel[@]}; do
if [ "$1" == "-prune" ]; then
echo "$f serait supprimé"
else
rm $f
echo "$f supprimé"
fi
done
#fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment