Skip to content

Commit

Permalink
improved script
Browse files Browse the repository at this point in the history
  • Loading branch information
herzrasen committed Jan 3, 2023
1 parent 286e77c commit 78a9af1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions shell/hist.zsh
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
autoload -U add-zsh-hook

hist_record() {
function TRAPINT() {
__HIST_COMMAND_INDEX=0
zle kill-whole-line
# return 128 plus the signal number
return $(( 128 + $1 ))
}

function hist-record() {
__HIST_COMMAND_INDEX=0
hist record "$1"
}
add-zsh-hook preexec hist_record
add-zsh-hook preexec hist-record

hist-backward-widget() {
__HIST_DIRECTION=1
command=$(hist get --index ${__HIST_COMMAND_INDEX:=0})
ret=$?
if [ $ret -ne 0 ]; then
zle reset-prompt
zle kill-whole-line
return $ret
fi
__HIST_COMMAND_INDEX=$((__HIST_COMMAND_INDEX+1))
Expand All @@ -34,14 +41,14 @@ hist-forward-widget() {
command=$(hist get --index $__HIST_COMMAND_INDEX)
ret=$?
if [ $ret -ne 0 ]; then
zle reset-prompt
zle kill-whole-line
return $ret
fi
BUFFER=$command
CURSOR=$#BUFFER
else
__HIST_COMMAND_INDEX=0
zle push-line
zle kill-whole-line
fi
}

Expand All @@ -50,18 +57,12 @@ bindkey -M emacs "^[[B" hist-forward-widget
bindkey -M viins "^[[B" hist-forward-widget
bindkey -M vicmd "^[[B" hist-forward-widget

TRAPINT() {
__HIST_COMMAND_INDEX=0
# return 128 plus the signal number
return $(( 128 + $1 ))
}

hist-search-widget() {
zle push-line
zle kill-whole-line
command=$(hist search)
ret=$?
if [ $ret -ne 0 ]; then
zle reset-prompt
zle kill-whole-line
return $ret
fi
BUFFER=$command
Expand Down

0 comments on commit 78a9af1

Please sign in to comment.