Merge pull request #155741 from microsoft/tyriar/155648

Simplify bash PROMPT_COMMAND handling
This commit is contained in:
Daniel Imms
2022-07-20 08:00:32 -07:00
committed by GitHub

View File

@@ -33,12 +33,6 @@ if [ "$VSCODE_INJECTION" == "1" ]; then
builtin unset VSCODE_INJECTION
fi
# Disable shell integration if PROMPT_COMMAND is 2+ function calls since that is not handled.
if [[ "$PROMPT_COMMAND" =~ .*(' '.*\;)|(\;.*' ').* ]]; then
builtin unset VSCODE_SHELL_INTEGRATION
builtin return
fi
if [ -z "$VSCODE_SHELL_INTEGRATION" ]; then
builtin return
fi
@@ -155,25 +149,16 @@ __vsc_update_prompt
__vsc_prompt_cmd_original() {
__vsc_status="$?"
if [[ ${IFS+set} ]]; then
__vsc_original_ifs="$IFS"
fi
if [[ "$__vsc_original_prompt_command" =~ .+\;.+ ]]; then
IFS=';'
# Evaluate the original PROMPT_COMMAND similarly to how bash would normally
# See https://unix.stackexchange.com/a/672843 for technique
if [[ ${#__vsc_original_prompt_command[@]} -gt 1 ]]; then
for cmd in "${__vsc_original_prompt_command[@]}"; do
__vsc_status="$?"
eval "${cmd:-}"
done
else
IFS=' '
eval "${__vsc_original_prompt_command:-}"
fi
builtin read -ra ADDR <<<"$__vsc_original_prompt_command"
if [[ ${__vsc_original_ifs+set} ]]; then
IFS="$__vsc_original_ifs"
unset __vsc_original_ifs
else
unset IFS
fi
for ((i = 0; i < ${#ADDR[@]}; i++)); do
(exit ${__vsc_status})
builtin eval ${ADDR[i]}
done
__vsc_precmd
}
@@ -182,13 +167,9 @@ __vsc_prompt_cmd() {
__vsc_precmd
}
if [[ "$PROMPT_COMMAND" =~ (.+\;.+) ]]; then
# item1;item2...
__vsc_original_prompt_command="$PROMPT_COMMAND"
else
# (item1, item2...)
__vsc_original_prompt_command=${PROMPT_COMMAND[@]}
fi
# PROMPT_COMMAND arrays and strings seem to be handled the same (handling only the first entry of
# the array?)
__vsc_original_prompt_command=$PROMPT_COMMAND
if [[ -z "${bash_preexec_imported:-}" ]]; then
if [[ -n "$__vsc_original_prompt_command" && "$__vsc_original_prompt_command" != "__vsc_prompt_cmd" ]]; then