From e191b29748d58ab692d72bfa1e075dc1a76682b0 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Wed, 28 Feb 2024 12:23:35 +0100 Subject: [PATCH] zsh: bind C-p to atuin prefix search --- .zsh/history.zsh | 38 -------------------------------------- .zshrc | 5 +---- 2 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 .zsh/history.zsh diff --git a/.zsh/history.zsh b/.zsh/history.zsh deleted file mode 100644 index c46bf6f..0000000 --- a/.zsh/history.zsh +++ /dev/null @@ -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 diff --git a/.zshrc b/.zshrc index 75c2071..edc52aa 100644 --- a/.zshrc +++ b/.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