#!/usr/bin/env bash

function import() {
    for script in "$@"; do
        [[ -f "$script" ]] || { echo "import: not found: $script" >&2; return 1; }

        source "$script"
    done
}

function import_glob() {
    local dir="$1"
    local pattern="$2"
    local files=()

    [[ -d "$dir" ]] || return 0

    mapfile -d '' files < <(find "$dir" -name "$pattern" -print0 2>/dev/null)
    (( ${#files[@]} > 0 )) && import "${files[@]}"
}
