#!/bin/bash MUREX_SHELL="$(basename "$(readlink /proc/$$/exe)")" export MUREX_SHELL case "${MUREX_SHELL}" in zsh ) rc=${(%):-%N} ;; bash) rc="${BASH_SOURCE[0]}" ;; hook) rc="$0"; MUREX_SHELL="$1" ;; *) return esac if [ -z "${MUREX}" ]; then MUREX="$(dirname "$(realpath "${rc}")")" export MUREX fi run_hook() { if [ ! -d "$1" ]; then return; fi for handler in "$1"/*; do if [ -e "${handler}" ]; then case "${handler}" in *.sh|*.${MUREX_SHELL}) . "${handler}";; *.bg) "${handler}"&;; esac fi done } run_hooks() { for hook in "$@"; do run_hook "${MUREX}/hooks/${hook}"; run_hook "${MUREX}/private/hooks/${hook}"; done } if [ "$(basename -- "$0")" = "hook" ]; then if [ "$1" = "install" ]; then run_hooks sh install; else run_hooks "$@"; fi else rc="$(basename "${rc}")" case "${rc}" in '.zshenv') run_hooks shell;; '.zprofile') run_hooks shell-early-login;; '.zshrc') run_hooks shell-interactive;; '.zlogin') run_hooks shell-late-login;; '.zlogout') run_hooks shell-logout;; '.bash_profile') run_hooks shell shell-early-login shell-interactive shell-late-login;; '.bashrc') run_hooks shell shell-interactive;; '.bash_logout') run_hooks shell-logout;; *) run_hooks "${rc}";; esac fi