2024-03-10 00:16:29 +01:00
|
|
|
typeset -g MY_HISTORY_SEARCH_OFFSET=0
|
|
|
|
typeset -g MY_HISTORY_SEARCH_PREFIX=""
|
|
|
|
|
|
|
|
function my-history-prefix-search() {
|
|
|
|
if [[ $LASTWIDGET != my-history-prefix-search-* ]]; then
|
|
|
|
# start state machine
|
|
|
|
MY_HISTORY_SEARCH_OFFSET=-1
|
|
|
|
MY_HISTORY_SEARCH_PREFIX="$LBUFFER"
|
|
|
|
fi
|
|
|
|
local offset_delta=$1
|
|
|
|
local offset=$((MY_HISTORY_SEARCH_OFFSET + $offset_delta))
|
|
|
|
|
|
|
|
(($offset < 0)) && return
|
|
|
|
local result=$(
|
|
|
|
atuin search \
|
2024-03-24 15:10:07 +01:00
|
|
|
--filter-mode session \
|
2024-03-10 00:16:29 +01:00
|
|
|
--search-mode prefix \
|
|
|
|
--limit 1 \
|
|
|
|
--offset $offset \
|
|
|
|
--format '{command}' \
|
2024-03-25 19:29:27 +01:00
|
|
|
"$MY_HISTORY_SEARCH_PREFIX" ||
|
|
|
|
atuin search \
|
|
|
|
--search-mode prefix \
|
|
|
|
--limit 1 \
|
|
|
|
--offset $offset \
|
|
|
|
--format '{command}' \
|
|
|
|
"$MY_HISTORY_SEARCH_PREFIX" ||
|
2024-03-10 00:16:29 +01:00
|
|
|
)
|
|
|
|
if [[ -n "$result" ]]; then
|
|
|
|
BUFFER=$result
|
|
|
|
CURSOR=${#BUFFER}
|
|
|
|
MY_HISTORY_SEARCH_OFFSET=$offset
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function my-history-prefix-search-backward-widget() {
|
|
|
|
my-history-prefix-search +1
|
|
|
|
}
|
|
|
|
|
|
|
|
function my-history-prefix-search-forward-widget() {
|
|
|
|
my-history-prefix-search -1
|
|
|
|
}
|
|
|
|
|
|
|
|
zle -N my-history-prefix-search-backward-widget
|
|
|
|
zle -N my-history-prefix-search-forward-widget
|