From 108527775b3fa0b07aab3fd3b8c482467a3e733c Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Thu, 28 Sep 2017 13:31:27 +0300 Subject: [PATCH] Show last error code in Bash prompt. --- .bashrc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index 7afbbc0..2b00d21 100644 --- a/.bashrc +++ b/.bashrc @@ -6,7 +6,6 @@ export LANG=en_US.UTF8 export HISTCONTROL=ignoreboth:erasedups export HISTSIZE=100000 export HISTFILESIZE=100000 -export PROMPT_COMMAND="history -a; $PROMPT_COMMAND" if [ -n "${BASH:-}" ] then shopt -s histappend @@ -24,6 +23,8 @@ then # shellcheck disable=SC2015 which aws_completer >/dev/null && complete -C 'aws_completer' aws || true + + export PROMPT_COMMAND="__bash_prompt" fi # make less more friendly for non-text input files, see lesspipe(1) @@ -188,5 +189,16 @@ match_ssl_pair () { return "$exitcode" } +__bash_prompt () { + local exitcode="$?" + history -a + if [ "$exitcode" -eq 0 ] + then + export PS1="\033[0m[Exit code: $exitcode] \u@\h:\w\$ " + else + export PS1="\033[0m[\033[31mExit code: $exitcode\033[0m] \u@\h:\w\$ " + fi +} + # shellcheck disable=SC1090 . "$HOME/Documents/Shore/bundle_certs/bundle_certs" -- GitLab