56 lines · 1.1 KB · executable
#!/usr/bin/env bash

#
# Void Linux package utilities
#

packagesFile="$DOTFILES/void-packages.txt"

# Get user-installed xbps packages and strip version info.
#
# We could also list all installed packages with:
#    xbps-query -l | awk '{ print $2 }' | xargs -n1 xbps-uhelper getpkgname | fmt
get() {
    xbps-query -m \
        | xargs -n1 xbps-uhelper getpkgname \
        | sed -r 's/(base-system|grub-x86_64-efi|slack-desktop|discord)//' \
        | grep "\S"
}

# Write list of packages to disk.
save() {
   get > "$packagesFile"
}

# Install package and write update package listing to disk.
install() {
    sudo xbps-install $1
    if [[ $? == 0 ]]; then
        save
    fi
}

# Remove a package and write updated package listing to disk.
uninstall() {
    sudo xbps-remove $1
    if [[ $? == 0 ]]; then
        save
    fi
}