Created
January 10, 2020 18:59
-
-
Save chadaustin/f5c02832fcf0a508014f6cf3578243cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Append history | |
shopt -s histappend | |
#HISTCONTROL="ignorespace:ignoredups:erasedups" | |
HISTCONTROL=ignorespace:erasedups | |
HISTSIZE=100000 | |
HISTFILESIZE=-1 | |
CAA_AT_PROMPT=1 | |
function __caa_before_command { | |
if [ -z "$CAA_AT_PROMPT" ]; then | |
return | |
fi | |
unset CAA_AT_PROMPT | |
# TODO: better precision | |
CAA_COMMAND_START_TIME="$SECONDS" | |
} | |
trap '__caa_before_command' DEBUG | |
if [[ "$TERM" == "" || $- != *i* ]]; then | |
TERM_RESET= | |
TERM_RED= | |
TERM_GREEN= | |
TERM_YELLOW= | |
TERM_CYAN= | |
TERM_WHITE= | |
TERM_GRAY= | |
else | |
TERM_RESET=$(tput sgr0) | |
TERM_RED=$(tput setaf 1) | |
TERM_GREEN=$(tput setaf 2) | |
TERM_YELLOW=$(tput setaf 3) | |
TERM_CYAN=$(tput setaf 6) | |
TERM_WHITE=$(tput setaf 7) | |
TERM_GRAY=$(tput setaf 8) | |
fi | |
function __caa_prompt_command { | |
local EXIT="$?" | |
CAA_AT_PROMPT=1 | |
local ELAPSED=$((SECONDS - CAA_COMMAND_START_TIME)) | |
history -a | |
history -c | |
history -r | |
if [ "$EXIT" -ge "128" ]; then | |
local SIG=$((EXIT - 128)) | |
if [ "$SIG" -ge "32" ]; then | |
local SIGNAME="$SIG" | |
else | |
local SIGNAME="$SIG ($(kill -l $SIG))" | |
fi | |
echo "${TERM_RED}[Signal $SIGNAME]${TERM_RESET}" | |
elif [ "$EXIT" != "0" ]; then | |
if [ "$ELAPSED" -gt "5" ]; then | |
echo "${TERM_RED}[Exit $EXIT in ${ELAPSED}s]${TERM_RESET}" | |
else | |
echo "${TERM_RED}[Exit $EXIT]${TERM_RESET}" | |
fi | |
elif [ "$ELAPSED" -gt "5" ]; then | |
echo "${TERM_GREEN}[Success in ${ELAPSED}s]${TERM_RESET}" | |
fi | |
} | |
PROMPT_COMMAND=__caa_prompt_command | |
# Check window size on every new prompt. | |
shopt -s checkwinsize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment