Return with previous exit code in Bash prompt function (#199)

asdf-java prepends to `$PROMPT_COMMAND`, thus swallowing up the
previous command's exit code (normally the command the user
invoked). This is troublesome if the exit code is used in the
user's own prompt command, for example to output a different
prompt.
This commit is contained in:
Jens Broekens 2023-05-17 06:20:19 +02:00 committed by GitHub
parent ac1920f8c3
commit fb67e8ba4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,11 +15,13 @@ function _asdf_java_update_java_home() {
} }
function _asdf_java_prompt_command() { function _asdf_java_prompt_command() {
local e=$?
if [[ "${PWD}" == "${LAST_PWD}" ]]; then if [[ "${PWD}" == "${LAST_PWD}" ]]; then
return return $e
fi fi
LAST_PWD="${PWD}" LAST_PWD="${PWD}"
_asdf_java_update_java_home _asdf_java_update_java_home
return $e
} }
if ! [[ "${PROMPT_COMMAND:-}" =~ _asdf_java_prompt_command ]]; then if ! [[ "${PROMPT_COMMAND:-}" =~ _asdf_java_prompt_command ]]; then