mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-11 07:10:39 +02:00
feat: crude atuin backward search
This commit is contained in:
parent
0d19ea4437
commit
6a6d6ce97d
1 changed files with 33 additions and 19 deletions
|
@ -11,8 +11,16 @@ if autoload history-search-end; then
|
||||||
zle -N history-beginning-search-forward-end history-search-end
|
zle -N history-beginning-search-forward-end history-search-end
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function str_to_hex() {
|
||||||
|
local str="$1"
|
||||||
|
for (( i=0; i<${#str}; i++ )); do
|
||||||
|
printf "%x" "'${str:$i:1}"
|
||||||
|
done
|
||||||
|
}
|
||||||
function atuin-beginning-search-backward() {
|
function atuin-beginning-search-backward() {
|
||||||
LBUFFER="hi du fette sau $LBUFFER"
|
if OUT=$(nix run p#sqlite -- ~/.local/share/atuin/history.db 'SELECT command FROM history WHERE command LIKE cast(x'"'$(str_to_hex ls)'"' as text) || "%" ORDER BY timestamp DESC LIMIT 1 OFFSET '"$OFFSET"); then
|
||||||
|
BUFFER="$OUT"
|
||||||
|
fi
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
}; zle -N atuin-beginning-search-backward
|
}; zle -N atuin-beginning-search-backward
|
||||||
|
|
||||||
|
@ -22,8 +30,11 @@ function atuin-beginning-search-backward-end() {
|
||||||
if [[ $LASTWIDGET = atuin-beginning-search-*-end ]]; then
|
if [[ $LASTWIDGET = atuin-beginning-search-*-end ]]; then
|
||||||
# Last widget called set $MARK.
|
# Last widget called set $MARK.
|
||||||
CURSOR=$MARK
|
CURSOR=$MARK
|
||||||
|
OFFSET=$((OFFSET + 1))
|
||||||
else
|
else
|
||||||
MARK=$CURSOR
|
MARK=$CURSOR
|
||||||
|
OFFSET=0
|
||||||
|
# TODO reset offset when query changes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if zle atuin-beginning-search-backward; then
|
if zle atuin-beginning-search-backward; then
|
||||||
|
@ -44,52 +55,54 @@ function nop() {
|
||||||
function bindkeys() {
|
function bindkeys() {
|
||||||
[[ "$#" -eq 2 ]] || return
|
[[ "$#" -eq 2 ]] || return
|
||||||
local keys="$1"
|
local keys="$1"
|
||||||
|
local key
|
||||||
for key in ${(P)keys}; do
|
for key in ${(P)keys}; do
|
||||||
bindkey "$key" "$2"
|
bindkey "$key" "$2"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_keybinds() {
|
function setup_keybinds() {
|
||||||
local keys_Home=( "${terminfo[khome]}" )
|
local keys_Home=( "${terminfo[khome]}" '\eOH' '\e[H' )
|
||||||
local keys_End=( "${terminfo[kend]}" )
|
local keys_End=( "${terminfo[kend]}" '\eOF' '\e[F' )
|
||||||
local keys_Insert=( "${terminfo[kich1]}" )
|
local keys_Insert=( "${terminfo[kich1]}" '\e[2~' )
|
||||||
|
|
||||||
local keys_Tab=( "${terminfo[ht]}" )
|
local keys_Tab=( "${terminfo[ht]}" '\t' )
|
||||||
local keys_ShiftTab=( "${terminfo[kcbt]}" )
|
local keys_ShiftTab=( "${terminfo[kcbt]}" '\eOZ' '\e[Z' )
|
||||||
|
|
||||||
local keys_ShiftBackspace=( "${terminfo[kbs]}" )
|
local keys_Backspace=( "${terminfo[kbs]}" '^?')
|
||||||
local keys_CtrlBackspace=( "${terminfo[cub1]}" )
|
local keys_CtrlBackspace=( "${terminfo[cub1]}" '^H')
|
||||||
|
local keys_AltBackspace=( "${terminfo[kbs]}" '\e^?')
|
||||||
|
|
||||||
local keys_Delete=( "${terminfo[kdch1]}" )
|
local keys_Delete=( "${terminfo[kdch1]}" '\e[3~' )
|
||||||
local keys_ShiftDelete=( "${terminfo[kDC]}" )
|
local keys_ShiftDelete=( "${terminfo[kDC]}" '\e[3;2~' )
|
||||||
local keys_CtrlDelete=( '\e[3;5~' )
|
local keys_CtrlDelete=( '\e[3;5~' )
|
||||||
local keys_AltDelete=( '\e[3;3~' )
|
local keys_AltDelete=( '\e[3;3~' )
|
||||||
|
|
||||||
local keys_Up=( "${terminfo[kcuu1]}" '\eOA' '\e[A' )
|
local keys_Up=( "${terminfo[kcuu1]}" '\eOA' '\e[A' )
|
||||||
local keys_ShiftUp=( "${terminfo[kri]}" )
|
local keys_ShiftUp=( "${terminfo[kri]}" '\e[1;2A' )
|
||||||
local keys_CtrlUp=( '\e[1;5A' )
|
local keys_CtrlUp=( '\e[1;5A' )
|
||||||
local keys_AltUp=( '\e[1;3A' )
|
local keys_AltUp=( '\e[1;3A' )
|
||||||
|
|
||||||
local keys_Down=( "${terminfo[kcud1]}" '\eOB' '\e[B' )
|
local keys_Down=( "${terminfo[kcud1]}" '\eOB' '\e[B' )
|
||||||
local keys_ShiftDown=( "${terminfo[kind]}" )
|
local keys_ShiftDown=( "${terminfo[kind]}" '\e[1;2B' )
|
||||||
local keys_CtrlDown=( '\e[1;5B' )
|
local keys_CtrlDown=( '\e[1;5B' )
|
||||||
local keys_AltDown=( '\e[1;3B' )
|
local keys_AltDown=( '\e[1;3B' )
|
||||||
|
|
||||||
local keys_Right=( "${terminfo[kcuf1]}" '\eOC' '\e[C' )
|
local keys_Right=( "${terminfo[kcuf1]}" '\eOC' '\e[C' )
|
||||||
local keys_ShiftRight=( "${terminfo[kLFT]}" )
|
local keys_ShiftRight=( "${terminfo[kRIT]}" '\e[1;2C' )
|
||||||
local keys_CtrlRight=( '\e[1;5C' )
|
local keys_CtrlRight=( '\e[1;5C' )
|
||||||
local keys_AltRight=( '\e[1;3C' )
|
local keys_AltRight=( '\e[1;3C' )
|
||||||
|
|
||||||
local keys_Left=( "${terminfo[kcub1]}" '\eOD' '\e[D' )
|
local keys_Left=( "${terminfo[kcub1]}" '\eOD' '\e[D' )
|
||||||
local keys_ShiftLeft=( "${terminfo[kRIT]}" )
|
local keys_ShiftLeft=( "${terminfo[kLFT]}" '\e[1;2D' )
|
||||||
local keys_CtrlLeft=( '\e[1;5D' )
|
local keys_CtrlLeft=( '\e[1;5D' )
|
||||||
local keys_AltLeft=( '\e[1;3D' )
|
local keys_AltLeft=( '\e[1;3D' )
|
||||||
|
|
||||||
local keys_PageUp=( "${terminfo[kpp]}" )
|
local keys_PageUp=( "${terminfo[kpp]}" '\e[5~' )
|
||||||
local keys_ShiftPageUp=( "${terminfo[kPRV]}" )
|
local keys_ShiftPageUp=( "${terminfo[kPRV]}" '\e[5;2~' )
|
||||||
|
|
||||||
local keys_PageDown=( "${terminfo[knp]}" )
|
local keys_PageDown=( "${terminfo[knp]}" '\e[6~' )
|
||||||
local keys_ShiftPageDown=( "${terminfo[kNXT]}" )
|
local keys_ShiftPageDown=( "${terminfo[kNXT]}" '\e[6;2~' )
|
||||||
|
|
||||||
bindkeys keys_Home beginning-of-line
|
bindkeys keys_Home beginning-of-line
|
||||||
bindkeys keys_End end-of-line
|
bindkeys keys_End end-of-line
|
||||||
|
@ -98,7 +111,8 @@ function setup_keybinds() {
|
||||||
bindkeys keys_Tab fzf-tab-complete
|
bindkeys keys_Tab fzf-tab-complete
|
||||||
bindkeys keys_ShiftTab nop
|
bindkeys keys_ShiftTab nop
|
||||||
|
|
||||||
bindkeys keys_ShiftBackspace backward-kill-word
|
bindkeys keys_Backspace backward-delete-char
|
||||||
|
bindkeys keys_AltBackspace backward-kill-word
|
||||||
bindkeys keys_CtrlBackspace backward-kill-line
|
bindkeys keys_CtrlBackspace backward-kill-line
|
||||||
|
|
||||||
bindkeys keys_Delete delete-char
|
bindkeys keys_Delete delete-char
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue