Files
omarchy/bin/omarchy-pkg-drop
T

32 lines
753 B
Bash
Executable File

#!/bin/bash
# omarchy:summary=Remove all the named packages from the system if they're installed (otherwise ignore).
# omarchy:args=<packages...>
# omarchy:requires-sudo=true
installed=()
declare -A installed_exact=()
declare -A selected=()
if ! installed_packages=$(pacman -Qq); then
echo "Unable to query installed packages; no packages were removed." >&2
exit 1
fi
while IFS= read -r package_name; do
if [[ -n $package_name ]]; then
installed_exact[$package_name]=1
fi
done <<< "$installed_packages"
for pkg in "$@"; do
if [[ -n ${installed_exact[$pkg]} && -z ${selected[$pkg]} ]]; then
installed+=("$pkg")
selected[$pkg]=1
fi
done
if (( ${#installed[@]} > 0 )); then
sudo pacman -Rns --noconfirm "${installed[@]}"
fi