#!/bin/bash echo "Removing unused Flatpak runtimes..." sudo flatpak uninstall --system --unused -y --noninteractive flatpak uninstall --user --unused -y --noninteractive if command -v paccache &>/dev/null; then echo "Trimming pacman package cache..." sudo paccache -rk2 sudo paccache -ruk0 fi # Remove packages that were installed as dependencies and are no longer needed # (packages something lists as an optional dependency are kept). To keep one # you use directly: sudo pacman -D --asexplicit mapfile -t ORPHANS < <(pacman -Qtdq 2>/dev/null) if (( ${#ORPHANS[@]} > 0 )); then echo "Removing packages no longer needed by anything:" printf ' %s\n' "${ORPHANS[@]}" sudo pacman -Rns --noconfirm "${ORPHANS[@]}" || exit 1 echo "To get one of these back, reinstall it with: sudo pacman -S " fi