# enable extended debugging and set a trap to run `check_command_exists` before each command
shopt -s extdebug
trap '[[ "${BASH_COMMAND}" =~ ^\s*([^=\(]|$) ]] || check_command_exists "${BASH_COMMAND}"' DEBUG

# check if a command exists and run it with its arguments if it does
check_command_exists() {
  command -v "${1%% *}" >/dev/null 2>&1;
  {
    shift; "$@";
  } || true;
}

