Skip to content

Instantly share code, notes, and snippets.

@echosa
Last active January 28, 2020 02:58
Show Gist options
  • Save echosa/390b968093c37e459ec38cd510d30de0 to your computer and use it in GitHub Desktop.
Save echosa/390b968093c37e459ec38cd510d30de0 to your computer and use it in GitHub Desktop.
All The Things - Package Manager Manager
#!/bin/bash
PACKAGE_MANAGERS=()
PACKAGE_MANAGERS+=("apt")
apt_clean() {
sudo apt autoremove
}
apt_search() {
apt search $1
}
apt_search_exact() {
apt search ^$1$
}
apt_upgrade() {
sudo apt update; sudo apt upgrade
}
PACKAGE_MANAGERS+=("brew")
brew_clean() {
brew cleanup
}
brew_search() {
brew search $1
}
brew_search_exact() {
brew search /^$1$/
}
brew_upgrade() {
brew update; brew upgrade
}
PACKAGE_MANAGERS+=("flatpak")
flatpak_search() {
flatpak search $1
}
flatpak_search_exact() {
flatpak_search $1
}
flatpak_upgrade() {
flatpak update
}
PACKAGE_MANAGERS+=("guix")
guix_clean() {
guix package --delete-generations; guix gc --collect-garbage; guix gc --list-dead
}
guix_search() {
guix package -A $1
}
guix_search_exact() {
guix package -A ^$1$
}
guix_upgrade() {
guix pull; guix package -u
}
PACKAGE_MANAGERS+=("snap")
snap_search() {
snap find $1
}
snap_search_exact() {
snap_search $1
}
snap_upgrade() {
sudo snap refresh
}
for PACKAGE_MANAGER in "${PACKAGE_MANAGERS[@]}"; do
echo "####################"
echo "####################"
echo $PACKAGE_MANAGER
echo "####################"
if [ -x "$(command -v $PACKAGE_MANAGER)" ]; then
COMMAND_FUNCTION=$PACKAGE_MANAGER"_"$1
if [ "$(type -t $COMMAND_FUNCTION)" = "function" ]; then
eval ${COMMAND_FUNCTION} $2
else
echo Package manager $PACKAGE_MANAGER has no defined $1 command.
fi
else
echo Package manager $PACKAGE_MANAGER not found.
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment