#!/usr/bin/env fish
#
# Cleanup untagged images from buildah and podman
#

set pre (df --sync --total -k --output=used | tail -n 1)

echo "Removing build images..."
buildah rm -a && echo "Done."
echo
echo "Pruning images..."
podman image prune -f | grep -Ev '^[0-9a-f]{64}$'
if [ $pipestatus[1] = 0 ]
    echo "Done."
end

set post (df --sync --total -k --output=used | tail -n 1)

python3 -c 'import sys; print("{:>10,} KiB recovered".format(int(sys.argv[1]) - int(sys.argv[2])))' \
    $pre $post

