mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-11 17:40:49 +01:00
37 lines
996 B
Bash
37 lines
996 B
Bash
autoload -U add-zsh-hook
|
|
add-zsh-hook zshaddhistory _hishtory_add
|
|
add-zsh-hook precmd _hishtory_precmd
|
|
|
|
_hishtory_first_prompt=1
|
|
|
|
function _hishtory_add() {
|
|
# Runs after <ENTER>, but before the command is executed
|
|
# $1 contains the command that was run
|
|
_hishtory_command=$1
|
|
_hishtory_start_time=`date +%s`
|
|
}
|
|
|
|
function _hishtory_precmd() {
|
|
# Runs after the command is executed in order to render the prompt
|
|
# $? contains the exit code
|
|
_hishtory_exit_code=$?
|
|
if [ -n "$_hishtory_first_prompt" ]; then
|
|
unset _hishtory_first_prompt
|
|
return
|
|
fi
|
|
(hishtory saveHistoryEntry zsh $_hishtory_exit_code "$_hishtory_command" $_hishtory_start_time &)
|
|
}
|
|
|
|
_hishtory_widget() {
|
|
BUFFER=$(hishtory tquery $BUFFER | tr -d '\n')
|
|
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
|