Skip to content

Instantly share code, notes, and snippets.

@y16ra
Last active July 31, 2024 00:31
Show Gist options
  • Save y16ra/ecaedad1cccc12e4df23ee361c5a3203 to your computer and use it in GitHub Desktop.
Save y16ra/ecaedad1cccc12e4df23ee361c5a3203 to your computer and use it in GitHub Desktop.
Interactive History Search
HIST_STAMPS="yyyy-mm-dd"
# fzf history
function fzf-select-history() {
local selected=$(history -n -r 1 | fzf --query "$LBUFFER" --reverse)
if [ -n "$selected" ]; then
BUFFER=$(echo "$selected" | awk '{$1=""; $2=""; print $0}' | sed 's/^[ \t]*//')
CURSOR=$#BUFFER
zle reset-prompt
fi
}
zle -N fzf-select-history
bindkey '^r' fzf-select-history
@y16ra
Copy link
Author

y16ra commented Jul 31, 2024

Each history entry shows the date, time, and the full command.
Format example: 2023-07-31 09:25 vi .zshrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment