]> git.sev.monster Git - dotfiles.git/commitdiff
zsh: first attempt at interactive history delete
authorsev <git@sev.monster>
Mon, 23 Dec 2024 01:40:34 +0000 (19:40 -0600)
committersev <git@sev.monster>
Mon, 23 Dec 2024 01:40:34 +0000 (19:40 -0600)
kinda works but still has not understood edge cases where sed doesn't play nice

etc/zsh/.zshrc

index 9d2539fb8e9c308cb138e39ad6476f44654becea..d71861ea3fd2d1840aeda051ac7be6f56a21cadc 100644 (file)
@@ -209,9 +209,28 @@ unset a k v
 # bash-style reverse-search-history (i.e. reverse-i-search)
 if [[ -v commands[fzf] ]] {
     function _history-incremental-pattern-search-fzf {
-        l=(${(f)"$(fc -li -1 0 | fzf -e -m -n 1 +s --preview-window=hidden ${BUFFER:+-q $BUFFER})"})
+        fc -AI
+        # XXX: this shit is cursed and sometimes doesn't work
+        # TODO: remove doesn't work over newlines, fzf replaces them with \n,
+        #       and sed of course hates newlines and would need to be massaged
+        # TODO: interactive history refresh... can't get zsh to load histfile:
+        # +reload(HISTFILE='"$h HISTSIZE=$HISTSIZE SAVEHIST=$SAVEHIST \$0 +Z -dfimc 'setopt EXTENDED_HISTORY;fc -R \$HISTFILE;$c' </dev/null 2>&1)" \
+        local c='fc -lt%F -1 0'
+        local h="'${HISTFILE//\'/\'\\\'\'}'"
+        local l=(${(f)"$($=c | fzf \
+            --scheme=history -e -n 1,3.. \
+            +s \
+            -m --bind 'ctrl-d:execute-silent(sed -i -f <(
+                sed -Ee '\''s/[$*.[\^/]/\\&/g;s~.*~/^\\(: [0-9]\\+:[0-9]\\+;\\)\\?&$/d~'\'' {+f3..}
+              ) '$h')+abort' \
+            --preview-window=hidden --height=20% \
+            --with-shell "${0:a} -dfc" \
+            ${BUFFER:+-q $BUFFER})"})
+        # XXX: this sucks, I hate this. no other way to flush internal history?
+        HISTFILE= HISTSIZE=0 fc -p $HISTFILE $HISTSIZE $SAVEHIST
         l=$(for x ("${l[@]}") { echo ${${=x}:3}; })
         BUFFER="$l"
+        zle reset-prompt
     }
     zle -N _history-incremental-pattern-search-fzf
     bindkey '^R' _history-incremental-pattern-search-fzf
This page took 0.045422 seconds and 4 git commands to generate.