mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-25 06:22:24 +02:00
Rename precommand and postcommand and ensure that hishtory doesn't stomp any existing PROMPT_COMMAND
This commit is contained in:
parent
23d85c81e5
commit
bf66f9f4fe
@ -1,7 +1,8 @@
|
|||||||
# This script should be sourced inside of .bashrc to integrate bash with hishtory
|
# This script should be sourced inside of .bashrc to integrate bash with hishtory
|
||||||
|
# This is the same as config.sh, except it doesn't run the save process in the background. This is crucial to making tests reproducible.
|
||||||
|
|
||||||
# Implementation of PreCommand and PostCommand based on https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/
|
# Implementation of running before/after every command based on https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/
|
||||||
function PreCommand() {
|
function __hishtory_precommand() {
|
||||||
if [ -z "$HISHTORY_AT_PROMPT" ]; then
|
if [ -z "$HISHTORY_AT_PROMPT" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -10,10 +11,10 @@ function PreCommand() {
|
|||||||
# Run before every command
|
# Run before every command
|
||||||
HISHTORY_START_TIME=`date +%s`
|
HISHTORY_START_TIME=`date +%s`
|
||||||
}
|
}
|
||||||
trap "PreCommand" DEBUG
|
trap "__hishtory_precommand" DEBUG
|
||||||
|
|
||||||
HISHTORY_FIRST_PROMPT=1
|
HISHTORY_FIRST_PROMPT=1
|
||||||
function PostCommand() {
|
function __hishtory_postcommand() {
|
||||||
EXIT_CODE=$?
|
EXIT_CODE=$?
|
||||||
HISHTORY_AT_PROMPT=1
|
HISHTORY_AT_PROMPT=1
|
||||||
|
|
||||||
@ -25,4 +26,4 @@ function PostCommand() {
|
|||||||
# Run after every prompt
|
# Run after every prompt
|
||||||
(hishtory saveHistoryEntry bash $EXIT_CODE "`history 1`" $HISHTORY_START_TIME &)
|
(hishtory saveHistoryEntry bash $EXIT_CODE "`history 1`" $HISHTORY_START_TIME &)
|
||||||
}
|
}
|
||||||
PROMPT_COMMAND="PostCommand"
|
PROMPT_COMMAND="__hishtory_postcommand; $PROMPT_COMMAND"
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# This script should be sourced inside of .bashrc to integrate bash with hishtory
|
# This script should be sourced inside of .bashrc to integrate bash with hishtory
|
||||||
# This is the same as config.sh, except it doesn't run the save process in the background. This is crucial to making tests reproducible.
|
# This is the same as config.sh, except it doesn't run the save process in the background. This is crucial to making tests reproducible.
|
||||||
|
|
||||||
# Implementation of PreCommand and PostCommand based on https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/
|
# Implementation of running before/after every command based on https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/
|
||||||
function PreCommand() {
|
function __hishtory_precommand() {
|
||||||
if [ -z "$HISHTORY_AT_PROMPT" ]; then
|
if [ -z "$HISHTORY_AT_PROMPT" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -11,10 +11,10 @@ function PreCommand() {
|
|||||||
# Run before every command
|
# Run before every command
|
||||||
HISHTORY_START_TIME=`date +%s`
|
HISHTORY_START_TIME=`date +%s`
|
||||||
}
|
}
|
||||||
trap "PreCommand" DEBUG
|
trap "__hishtory_precommand" DEBUG
|
||||||
|
|
||||||
HISHTORY_FIRST_PROMPT=1
|
HISHTORY_FIRST_PROMPT=1
|
||||||
function PostCommand() {
|
function __hishtory_postcommand() {
|
||||||
EXIT_CODE=$?
|
EXIT_CODE=$?
|
||||||
HISHTORY_AT_PROMPT=1
|
HISHTORY_AT_PROMPT=1
|
||||||
|
|
||||||
@ -26,4 +26,4 @@ function PostCommand() {
|
|||||||
# Run after every prompt
|
# Run after every prompt
|
||||||
hishtory saveHistoryEntry bash $EXIT_CODE "`history 1`" $HISHTORY_START_TIME
|
hishtory saveHistoryEntry bash $EXIT_CODE "`history 1`" $HISHTORY_START_TIME
|
||||||
}
|
}
|
||||||
PROMPT_COMMAND="PostCommand"
|
PROMPT_COMMAND="__hishtory_postcommand; $PROMPT_COMMAND"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user