hishtory/client/lib/config.sh

29 lines
791 B
Bash
Raw Normal View History

2022-01-10 01:39:13 +01:00
# This script should be sourced inside of .bashrc to integrate bash with hishtory
# Implementation of running before/after every command based on https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/
function __hishtory_precommand() {
2022-01-10 01:39:13 +01:00
if [ -z "$HISHTORY_AT_PROMPT" ]; then
return
fi
unset HISHTORY_AT_PROMPT
# Run before every command
HISHTORY_START_TIME=`date +%s`
2022-01-10 01:39:13 +01:00
}
trap "__hishtory_precommand" DEBUG
2022-01-10 01:39:13 +01:00
HISHTORY_FIRST_PROMPT=1
function __hishtory_postcommand() {
2022-04-08 07:53:39 +02:00
EXIT_CODE=$?
2022-01-10 01:39:13 +01:00
HISHTORY_AT_PROMPT=1
if [ -n "$HISHTORY_FIRST_PROMPT" ]; then
unset HISHTORY_FIRST_PROMPT
return
fi
# Run after every prompt
(hishtory saveHistoryEntry bash $EXIT_CODE "`history 1`" $HISHTORY_START_TIME &)
2022-01-10 01:39:13 +01:00
}
PROMPT_COMMAND="__hishtory_postcommand; $PROMPT_COMMAND"