diff --git a/src/init/starship.bash b/src/init/starship.bash index 1e6a972b..e08a9fbd 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -65,8 +65,8 @@ starship_precmd() { # command pipeline, which may rely on it. _starship_set_return "$STARSHIP_CMD_STATUS" - if [[ -n "${_PRESERVED_PROMPT_COMMAND-}" ]]; then - eval "$_PRESERVED_PROMPT_COMMAND" + if [[ -n "${STARSHIP_PROMPT_COMMAND-}" ]]; then + eval "$STARSHIP_PROMPT_COMMAND" fi local -a ARGS=(--terminal-width="${COLUMNS}" --status="${STARSHIP_CMD_STATUS}" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="${NUM_JOBS}") @@ -110,12 +110,13 @@ else # We want to avoid destroying an existing DEBUG hook. If we detect one, create # a new function that runs both the existing function AND our function, then # re-trap DEBUG to use this new function. This prevents a trap clobber. - dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')" - if [[ -z "$dbg_trap" ]]; then + eval "STARSHIP_DEBUG_TRAP=($(trap -p DEBUG))" + STARSHIP_DEBUG_TRAP=("${STARSHIP_DEBUG_TRAP[2]}") + if [[ -z "$STARSHIP_DEBUG_TRAP" ]]; then trap 'starship_preexec "$_"' DEBUG - elif [[ "$dbg_trap" != 'starship_preexec "$_"' && "$dbg_trap" != 'starship_preexec_all "$_"' ]]; then + elif [[ "$STARSHIP_DEBUG_TRAP" != 'starship_preexec "$_"' && "$STARSHIP_DEBUG_TRAP" != 'starship_preexec_all "$_"' ]]; then starship_preexec_all() { - local PREV_LAST_ARG=$1 ; $dbg_trap; starship_preexec; : "$PREV_LAST_ARG"; + local PREV_LAST_ARG=$1 ; eval -- "$STARSHIP_DEBUG_TRAP"; starship_preexec; : "$PREV_LAST_ARG"; } trap 'starship_preexec_all "$_"' DEBUG fi @@ -130,7 +131,7 @@ else # Prepending to PROMPT_COMMAND breaks "command duration" module. # So, we are preserving the existing PROMPT_COMMAND # which will be executed later in the starship_precmd function - _PRESERVED_PROMPT_COMMAND="$PROMPT_COMMAND" + STARSHIP_PROMPT_COMMAND="$PROMPT_COMMAND" PROMPT_COMMAND="starship_precmd" fi fi