From 7ca0026b377aebf597cb6a0008f9f206817221ed Mon Sep 17 00:00:00 2001 From: Robert Meerman Date: Thu, 30 Apr 2015 20:42:48 +0100 Subject: [PATCH] _LAST_COMMAND_INDICATOR_ now displays symbolic names of signals --- gitprompt.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gitprompt.sh b/gitprompt.sh index 9c56dec..a534525 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -185,6 +185,24 @@ git_prompt_reset() { done } +# gp_format_exit_status RETVAL +# +# echos the symbolic signal name represented by RETVAL if the process was +# signalled, otherwise echos the original value of RETVAL + +gp_format_exit_status() { + local RETVAL="$1" + local SIGNAL + # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL + # is echoed verbatim) + if [ "${RETVAL}" -gt 128 ] 2>/dev/null; then + SIGNAL=$(( ${RETVAL} - 128 )) + kill -l "${SIGNAL}" 2>/dev/null || echo "${RETVAL}" + else + echo "${RETVAL}" + fi +} + function git_prompt_config() { #Checking if root to change output @@ -214,6 +232,7 @@ function git_prompt_config() fi # replace _LAST_COMMAND_STATE_ token with the actual state + GIT_PROMPT_LAST_COMMAND_STATE=$(gp_format_exit_status ${GIT_PROMPT_LAST_COMMAND_STATE}) LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR//_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" # Do this only once to define PROMPT_START and PROMPT_END