xpm

x package manager, a uniform interface to various POSIX package managers
git clone git://src.gearsix.net/xpm
Log | Files | Refs | Atom | README

commit 9ab84dfbea208d30aa347a01093f823cd7e3f2ec
parent 28f61b61e3cc3f4dcbfbf7660e03b9e175a6db6a
Author: gearsix <gearsix@tuta.io>
Date:   Fri,  1 Apr 2022 12:21:38 +0100

added hook support

Diffstat:
MREADME.md | 23++++++++++++++---------
Mxpm.sh | 39++++++++++++++++++++++++++++++---------
2 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/README.md b/README.md @@ -7,13 +7,6 @@ A sh script to provide a generic interface to whatever package manager your syst The goal of this project is to avoid the requirement for doing the mental check required when interfacing with your systems package manager, useful if you hop between systems frequently. -## configure - -It also tracks installed/uninstalled packages (only what you've requested for install, not including its dependencies) in `~/.local/share/xpm/installed.txt`. - -Tracking installed packages can be disabled by setting *XPM_NOTRACK* to 1, either in your environment. - - ## install `install ./xpm.sh [INSTALL DIR]/xpm` @@ -24,9 +17,21 @@ Tracking installed packages can be disabled by setting *XPM_NOTRACK* to 1, eithe - *~/.local/bin* -## notes +## configure + +**tracking** + +xpm keeps track of installed/uninstalled packages (only what you've requested for install, not including its dependencies) in `~/.local/share/xpm/installed.txt`. + +This behaviour can be disabled by setting *XPM_NOTRACK* to 1, either in your environment. + +**hooks** + +xpm supports 'hooks' (inspired by git-hooks). A 'hook' is a script that gets executed *after* running the specified command. + +All you need to do is add the script file to execute in `~/.config/xpm/hooks` and make sure it's executable. -- Add hooking (รก la githooks) +This is useful if you install package outside of the package manager that require a seperate command to execute, or if you want to add additional behaviour to the default xpm commands. ## authors diff --git a/xpm.sh b/xpm.sh @@ -1,6 +1,7 @@ #!/usr/bin/env sh xpm="" +HOOKS_DIR=~/.config/xpm/hooks INSTALLED=~/.local/share/xpm/installed.txt usage() { @@ -14,6 +15,21 @@ usage() { echo "search search the repositories for [PKG]" echo "query query [PKG] to see if it's installed" echo "update update all packages on the system" + echo "" + echo "See the README.md file for more details" +} + +exec_hooks() { + if [ $1 = "" ]; then return; fi + + if [ ! -e $HOOKS_DIR ]; then mkdir -p $HOOKS_DIR; fi + + for f in $HOOKS_DIR/*; do + if [ "$(basename $f)" = "$1" ]; then + echo "executing $f" + exec $f + fi + done } installed_add() { @@ -46,18 +62,18 @@ unknown_pm() { } xpm_install() { - if [ $(command -v apt) ]; then - sudo apt install $@ - elif [ $(command -v zypper) ]; then - sudo zypper install $@ - elif [ $(command -v xbps-install) ]; then - sudo xbps-install -Rs $@ - else unknown_pm; fi + if [ $(command -v apt) ]; then + sudo apt install $@ + elif [ $(command -v zypper) ]; then + sudo zypper install $@ + elif [ $(command -v xbps-install) ]; then + sudo xbps-install -Rs $@ + else unknown_pm; fi } xpm_remove() { if [ $(command -v apt) ]; then - sudo apt remove $@ && sudo apt autoremove -y + sudo apt remove $@ elif [ $(command -v zypper) ]; then sudo zypper remove -u $@ elif [ $(command -v xbps-remove) ]; then @@ -96,26 +112,31 @@ xpm_update() { } # main -case "$1" in +case "$1" in "i"|"in"|"install") shift xpm_install $@ && installed_add $@ + exec_hooks install ;; "r"|"rm"|"remove") shift xpm_remove $@ && installed_rm $@ + exec_hooks remove ;; "s"|"se"|"search") shift xpm_search $@ + exec_hooks search ;; "q"|"qry"|"query") shift xpm_query $@ + exec_hooks query ;; "u"|"up"|"update") shift xpm_update + exec_hooks update ;; *) usage