I am working on a zsh widget to fuzzy search history.
skim-history() {
origquery=${BUFFER}
output=$(history -1 1 | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort --exact)
if [ $? -eq 0 ]; then
BUFFER=$output
else
BUFFER=$origquery
fi
CURSOR=$#BUFFER
}
zle -N skim-history
bindkey '^R' skim-history
In history -1 1 | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort --exact
, sd is used instead of sed, which just removes numbers from the beginning. sk is an alternative for fzf.
This widget works pretty well except multi-line commands.
For example: it shows
like:
So, it replace newline with \n
. This is not something i want.
The command looks like the following in .zsh_history
file:
: 1657176206:0;function brcd() {\
cd $(broot --only-folders --hidden --cmd "$1;:pp")\
}\
What I found is !NUM get the history in correct format.
what changes do I need to make on my widget? How can I solve this problem?
history -1 1 | sd '^[ ]*[0-9]*[ ]*' ''
withfc -ln 1 -1
.fzf
which provides a "fuzzy search history".