kiss-hook

directory based kiss-hook manager
git clone git://git.ckyln.com/~cem/kiss-hook
Log | Files | Refs | README | LICENSE

commit 9a1671549acd2e8cad88b9a6693a4e1299185a4a
Author: Cem Keylan <cem@ckyln.com>
Date:   Sun, 19 Jul 2020 11:58:15 +0300

kiss-hook: initial commit

Diffstat:
ALICENSE | 21+++++++++++++++++++++
AREADME.md | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Akiss-hook | 22++++++++++++++++++++++
3 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Cem Keylan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md @@ -0,0 +1,51 @@ +kiss-hook manager +----------------- + +A directory based kiss-hook manager. I prefer to use this structure now after +having a single script with tons of `case` statements. It was hard to read and +hard to manage. + + +Installation +------------ + +If you want to install this, copy (or symlink) the `kiss-hook` file to the +directory you will be using as the hook directory. You will then need to +set the `$KISS_HOOK` variable pointing to this script. + +If you don't want to put this script to the hook directory, you can set the +environment variable `$KISS_HOOK_DIR` pointing to that directory. + + +Setting up hooks +---------------- + +For every hook, you can set up a directory or a single file with the name of the +hook. You can add a file named `lib` to the hook directory which will be sourced +for every hook. This is useful for using functions on multiple hook types. + +For example with the `post-build` hook, if you have package specific +configuration you create a directory named `post-build/`. In it you will have +files for all packages that you want to hook into. If you are hooking `gcc`, +`sbase`, and `less` you will have `post-build/gcc` `post-build/sbase`, and +`post-build/less` files. If you also want a hook that will affect every package +you will need to add `post-build/post-build`. + +If you don't have a package specific hook, but you want a hook that will deal +with every package (or a hook that doesn't even deal with packages), you can +simply create a file for the hook. + +Here is an example structure: + + + ├── kiss-hook + ├── lib + ├── post-build + │   ├── gcc + │   ├── less + │   ├── post-build + │   └── sbase + ├── post-install + │   └── linux + ├── pre-build + └── pre-fetch diff --git a/kiss-hook b/kiss-hook @@ -0,0 +1,22 @@ +#!/bin/sh -e +# shellcheck disable=1090 +# A directory based kiss-hook manager. + +# We don't want the package manager to exit because of an error here. +set +e + +hook() { + [ -e "${KISS_HOOK_DIR:=${KISS_HOOK%/*}}/$TYPE" ] || return 0 + [ -e "$KISS_HOOK_DIR/lib" ] && . "$KISS_HOOK_DIR/lib" + + [ -d "$KISS_HOOK_DIR/$TYPE" ] || { + . "$KISS_HOOK_DIR/$TYPE" + return + } + + [ -f "$KISS_HOOK_DIR/$TYPE/$TYPE" ] && . "$KISS_HOOK_DIR/$TYPE/$TYPE" + [ -f "$KISS_HOOK_DIR/$TYPE/$PKG" ] && . "$KISS_HOOK_DIR/$TYPE/$PKG" +} + +hook +set -e