# shellcheck shell=bash
### Constants ###

export CYAN_COLOR NO_COLOR
CYAN_COLOR=$(echo -e '\e[36m')
NO_COLOR=$(echo -e '\e[0m')

### Functions ###

function trap_commands() {
    # Function to print each bash command before it is executed
    trap 'cmd="$BASH_COMMAND" &&
          ! [[ "$cmd" =~ ^(echo|read|\[|while|for|local) ]] &&
          { [[ ! "$cmd" =~ \$\( ]] || cmd="${cmd@Q}"; } &&
          ctxt="${cluster:+[${cluster}]}" &&
          cmd=`eval echo "[${PWD##*/}]\$ $ctxt $cmd" 2>/dev/null` &&
          echo "${CYAN_COLOR}$cmd${NO_COLOR}" >&2; true' DEBUG
}

### Main ###

set -T
trap_commands
