#!/usr/bin/env bash

# shellcheck shell=bash

printf "REPL for %s\nUse ! to escape commands for the shell and :exit to exit\n" "$@"

notblank() {
  [ "$#" -gt 0 ]
}

while true; do
  printf "%s> " "$@"
  read -r || break
  notblank "${REPLY}" || continue
  [ "${REPLY}" = ":exit" ] && break
  if expr "X${REPLY}" : 'X.^!.*' >/dev/null; then
    eval command "${REPLY:1}"
  else
    eval command \"\$@\" "${REPLY}"
  fi
done
