#!/bin/bash set -euo pipefail this_dir="$(cd "$(dirname "$(realpath "$0")")" && pwd)" # list all commands, name only cmds() { find "${this_dir}" -maxdepth 1 -type f -name '*.sh' -print0 \ | xargs -0 -n 1 basename \ | sed 's/\.sh$//' \ | grep -Ev '^(main|common)$' \ | sort } # list all commands, name and description cmd_descriptions() { for cmd in $(cmds); do local cmd_sh="${this_dir}/${cmd}.sh" if [[ -x "${cmd_sh}" ]]; then local description description="$(bash "${cmd_sh}" -h 2>/dev/null | head -1 | sed 's/^[^:]*: *//')" if [[ -n "${description}" ]]; then printf "%-15s %s\n" "${cmd}" "${description}" else printf "%-15s\n" "${cmd}" fi fi done } if [[ "$#" -gt 0 && ("$1" == "-h" || "$1" == "--help") ]]; then cat < -h|--help szecret [args...] Available commands: $(cmd_descriptions | sed 's/^/ /') EOF exit 0 fi # check number of arguments > 1, error and exit if not # extract first argument, call script with same name using remaining arguments if [ $# -lt 1 ]; then >&2 cat <&2 echo "ERROR: no command named ${cmd}. Available: $(cmds | paste -sd ',' -)" exit 1 fi exec bash "${cmd_sh}" "$@"