Removes orphaned snap packages unless they are default providers or bases; also removes disabled snaps. Provides:
- Bash and Fish scripts
- Installer that places the script in /usr/local/bin
- systemd service and weekly timer
- Supports sudo or doas (auto-detect, overridable)
- The script uses
snap connectionsto find all snap packages that have no connections (i.e. are orphaned). - It filters out themes and slot-based connections.
- It extracts the package names from the output and stores them in the
orphanvariable. - It checks if any of the orphaned packages are default providers for other packages by parsing the
snap.yamlfiles. - If an orphaned package is a default provider, it will not be removed.
- Otherwise, the script will remove the orphaned package using
sudo snap remove.
- Save this script as a file (e.g.
orphand_snaps) - Make the script executable with
chmod +x remove_orphaned_snaps - Run the script with
./orphand_snaps
Bash:
# Install (auto-detect doas/sudo; override with set -x OVERRIDE_ELEVATION=doas|sudo)
orphand_snaps install
# Uninstall
orphand_snaps uninstallFish:
# Install (auto-detect doas/sudo; override with set -x OVERRIDE_ELEVATION=doas|sudo)
orphand_snaps install
# Uninstall
orphand_snaps uninstallThe last run records removed snaps to:
- State file: /var/lib/orphand_snaps/last_removed.txt
Usage:
# List snaps removed in the last run
orphand_snaps undo
# Reinstall a single snap
orphand_snaps undo SNAPNAME
# Reinstall all snaps removed in the last run
orphand_snaps undo all- Be careful when running this script, as it will permanently remove packages without prompting for confirmation.