#!/bin/sh -e
#
#+ memusg - Measure memory usage of processes
#+ usage:
#+     memusg [command] <args>
#
#- created: 2025-06-27
# END_OF_HEADER

# ---header variables
SCRIPT_HEADSIZE=$(head -200 "${0}" | grep -n "^# END_OF_HEADER" | cut -f1 -d:)
SCRIPT_NAME="$(basename "${0}")"
VERSION="1.0.0"

# ---usage functions
usage() {
  # printf "Usage: "
  head -"${SCRIPT_HEADSIZE:-99}" "${0}" \
    | grep -e "^#+" \
    | sed -e "s/^#+[ ]//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"
    # | sed -e "s/^#+[ ]*//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"

    # | sed -e "s/^#\///g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" \
    #   -e "s/\${VERSION}/${VERSION}/g"
}
usagefull() {
  head -"${SCRIPT_HEADSIZE:-99}" "${0}" \
    | grep -e "^#[%+-]" \
    | sed -e "s/^#[%+-][ ]//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"
}
scriptinfo() {
  head -"${SCRIPT_HEADSIZE:-99}" "${0}" \
    | grep -e "^#-" \
    | sed -e "s/^#-[ ]//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"
}

[ "$#" -gt 0 ] || {
  usage
  exit 1
}
