#!/bin/bash
# Vendored from https://github.com/bbugyi200/dotfiles via pyvendor on 2026-02-21

source "$(dirname "${BASH_SOURCE[0]}")/../lib/bugyi-260221.sh"

function run() {
  local count
  local delay_secs=1
  local msg="BAM"
  if [[ -n "$1" ]]; then
    count="$1"
    shift

    if ! [[ "${count}" =~ ^[0-9]+$ ]]; then
      die "USAGE: bam [count] [delay] [msg]\n\ncount MUST be an integer!"
    fi

    if [[ -n "$1" ]]; then
      delay_secs="$1"
      shift

      if [[ -n "$1" ]]; then
        msg="$1"
        shift
      fi
    fi
  else
    count=1
  fi

  for i in $(seq "$count"); do
    if [[ $i -gt 1 ]]; then
      sleep "${delay_secs}"
      if [[ "${msg}" == *" "* ]]; then
        printf "\n" 1>&2
      else
        printf " " 1>&2
      fi
    fi
    printf "${msg}" 1>&2
    printf "\a"
  done
  printf "\n" 1>&2
}

if [[ "${SCRIPTNAME}" == "$(basename "${BASH_SOURCE[0]}")" ]]; then
  run "$@"
fi
