zsh: bind C-p to atuin prefix search
This commit is contained in:
parent
6e7f8fc004
commit
e191b29748
2 changed files with 1 additions and 42 deletions
|
@ -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
5
.zshrc
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue