Created
September 24, 2015 02:01
-
-
Save PaulFurtado/7e7e762039756a732639 to your computer and use it in GitHub Desktop.
bashrc custom history
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
__lastcmd="$(history 1 | sed 's/^[ ]*[0-9]\+[ ]*//')" | |
HISTORY_FILE=~/.bash_eternal_history | |
function __prompt_cmd() { | |
local lastexit="$?" | |
local cmdstr="$(history 1 | sed 's/^[ ]*[0-9]\+[ ]*//')" | |
local logstr="DATE='$(date -Iseconds)' PID=$$ USER=$USER PWD='$PWD' EXIT_CODE=$lastexit COMMAND=$cmdstr" | |
if [[ "$cmdstr" != "$__lastcmd" ]] ; then | |
__lastcmd="$cmdstr" | |
echo "$logstr" >> $HISTORY_FILE | |
if [[ -n "$lastexit" && "$lastexit" -ne 0 ]]; then | |
local outtext="*** WARNING: The exit code was: $lastexit ***" | |
local RCol='\e[0m' | |
local Red='\e[0;31m' | |
echo -e "$Red$outtext$RCol" | |
fi | |
fi | |
} | |
PROMPT_COMMAND=__prompt_cmd | |
function histgrep { | |
(grep "$@" $HISTORY_FILE) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment