From 3b72b27e54f5d47f76b82d8506dde537db4ecb72 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Thu, 10 Oct 2024 20:19:32 -0700 Subject: [PATCH] atuin + fzf Even though I don't actually use Atuin, keep this code that I figured out how to do anyway --- .config/zsh/atuin.zsh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .config/zsh/atuin.zsh diff --git a/.config/zsh/atuin.zsh b/.config/zsh/atuin.zsh new file mode 100644 index 0000000..fe612ab --- /dev/null +++ b/.config/zsh/atuin.zsh @@ -0,0 +1,29 @@ +### atuin + +export ATUIN_NOBIND=true +eval "$(atuin init zsh)" + +# Reference: https://github.com/junegunn/fzf/discussions/3099 +fzf-atuin-history-widget() { + local selected + setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases noglob nobash_rematch 2> /dev/null + selected="$(atuin history list --format "{time} {command}" --reverse false --print0 | + FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n3..-2 --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '\t↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m --read0") \ + FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd))" + local ret=$? + if [ -n "$selected" ]; then + if [[ $(awk '{print $1; exit}' <<< "$selected") =~ ^[1-9][0-9]* ]]; then + zle vi-fetch-history -n $MATCH + else # selected is a custom query, not from history + LBUFFER="$selected" + fi + fi + zle -U "$selected" + zle kill-buffer + zle reset-prompt + return $ret +} +# zle -N fzf-history-widget +# bindkey '^R' fzf-history-widget + +# vim: ft=zsh