2022-04-18 08:06:01 +02:00
|
|
|
autoload -U add-zsh-hook
|
2022-04-18 04:54:17 +02:00
|
|
|
add-zsh-hook zshaddhistory _hishtory_add
|
|
|
|
add-zsh-hook precmd _hishtory_precmd
|
|
|
|
|
|
|
|
_hishtory_first_prompt=1
|
|
|
|
|
2023-12-31 22:00:56 +01:00
|
|
|
# For detecting color rendering support for this terminal, see #134
|
|
|
|
hishtory getColorSupport
|
|
|
|
export _hishtory_tui_color=$?
|
|
|
|
|
2022-04-18 04:54:17 +02:00
|
|
|
function _hishtory_add() {
|
|
|
|
# Runs after <ENTER>, but before the command is executed
|
|
|
|
# $1 contains the command that was run
|
|
|
|
_hishtory_command=$1
|
2023-11-18 21:19:19 +01:00
|
|
|
_hishtory_start_time=`hishtory getTimestamp`
|
2023-08-27 23:24:59 +02:00
|
|
|
if ! [ -z "$_hishtory_command " ]; then
|
2023-09-17 23:11:44 +02:00
|
|
|
(hishtory presaveHistoryEntry zsh "$_hishtory_command" $_hishtory_start_time &) # Background Run
|
|
|
|
# hishtory presaveHistoryEntry zsh "$_hishtory_command" $_hishtory_start_time # Foreground Run
|
2023-08-27 23:24:59 +02:00
|
|
|
fi
|
2022-04-18 04:54:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _hishtory_precmd() {
|
|
|
|
# Runs after the command is executed in order to render the prompt
|
2022-10-01 08:51:05 +02:00
|
|
|
# $? contains the exit code
|
2022-04-18 04:54:17 +02:00
|
|
|
_hishtory_exit_code=$?
|
2023-12-10 18:14:12 +01:00
|
|
|
if [ -n "${_hishtory_first_prompt:-}" ]; then
|
2022-04-18 04:54:17 +02:00
|
|
|
unset _hishtory_first_prompt
|
|
|
|
return
|
|
|
|
fi
|
2022-10-24 02:35:02 +02:00
|
|
|
(hishtory saveHistoryEntry zsh $_hishtory_exit_code "$_hishtory_command" $_hishtory_start_time &) # Background Run
|
|
|
|
# hishtory saveHistoryEntry zsh $_hishtory_exit_code "$_hishtory_command" $_hishtory_start_time # Foreground Run
|
2023-10-15 21:29:50 +02:00
|
|
|
(hishtory updateLocalDbFromRemote &)
|
2022-04-18 04:54:17 +02:00
|
|
|
}
|
2022-10-16 21:43:16 +02:00
|
|
|
|
|
|
|
_hishtory_widget() {
|
2022-11-20 07:27:08 +01:00
|
|
|
BUFFER=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery $BUFFER)
|
2022-10-16 21:43:16 +02:00
|
|
|
CURSOR=${#BUFFER}
|
|
|
|
zle reset-prompt
|
|
|
|
}
|
|
|
|
|
|
|
|
_hishtory_bind_control_r() {
|
|
|
|
zle -N _hishtory_widget
|
|
|
|
bindkey '^R' _hishtory_widget
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "$(hishtory config-get enable-control-r)" = true ] && _hishtory_bind_control_r
|
2023-12-20 00:57:32 +01:00
|
|
|
|
2023-12-21 02:08:30 +01:00
|
|
|
# If running in a test environment, force loading of compinit so that shell completions work.
|
|
|
|
# Otherwise, we respect the user's choice and only run compdef if the user has loaded compinit.
|
|
|
|
if [ -n "${HISHTORY_TEST:-}" ]; then
|
|
|
|
autoload -Uz compinit
|
|
|
|
compinit
|
|
|
|
fi
|
|
|
|
|
2024-02-09 07:44:35 +01:00
|
|
|
source <(hishtory completion zsh); which compdef >/dev/null 2>&1 && compdef _hishtory hishtory || true
|