Sample Header Ad - 728x90

Fuzzy Search History: Show History Keeping The Lines Intact For Multi-Line Commands

3 votes
1 answer
318 views
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 enter image description here like: enter image description here 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. enter image description here what changes do I need to make on my widget? How can I solve this problem?
Asked by Ahmad Ismail (2998 rep)
Jul 7, 2022, 07:29 AM
Last activity: Jul 14, 2022, 04:06 PM