zsh: bind C-p to atuin prefix search

This commit is contained in:
Daniel Lundin 2024-02-28 12:23:35 +01:00
parent 6e7f8fc004
commit e191b29748
2 changed files with 1 additions and 42 deletions

View file

@ -1,38 +0,0 @@
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 \
--search-mode prefix \
--limit 1 \
--offset $offset \
--format '{command}' \
"$MY_HISTORY_SEARCH_PREFIX"
)
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

5
.zshrc
View file

@ -96,12 +96,9 @@ _cwd_gitroot() {
}
zle -N _cwd_gitroot
source $HOME/.zsh/history.zsh
## Keybindings
bindkey -e
bindkey '^P' my-history-prefix-search-backward-widget
bindkey '^N' my-history-prefix-search-forward-widget
bindkey '^P' atuin-up-search
bindkey '^g' _jump