# bashrun remote interface ################################ -*- shell-script -*-

if [[ ! "$PROMPT_COMMAND" =~ ^trap\ DEBUG ]]; then
    PROMPT_COMMAND="trap DEBUG; shopt -s extdebug;$PROMPT_COMMAND"
fi

§bashrun-remote-trap () {
    trap "§bashrun-remote-action $1" DEBUG
}

§bashrun-remote-action () { 
    [[ "$BASH_COMMAND" =~ ^trap ]] && return 0
    bashrun2 do "${1:-run}" "${BASH_COMMAND:-$2}" && return 1
}

command_not_found_handle () {
    
    bashrun2 do run "$@"    

    local self="$(printf '#'; type command_not_found_handle)"
    unset -f command_not_found_handle
    $*
    eval "$self"
    return 127
}

bind '"\201": accept-line'; 

################################################################################

