You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I managed to add support for multi-line blocks, and I want to share it.
What I did was to retrieve the number event of the selected command in fzf, and then use history expansion zle expand-or-complete with that number so zsh gets the correct block of code.
functionfzf_history_search() {
# get event number
e_num=$(fc -l 0 | fzf --tac | awk '{print $1}')# HISTORY EXPANSION
BUFFER="!$e_num"
zle vi-fetch-history -n $BUFFER
zle expand-or-complete
}
I modified the script to my needs, didn't include some stuff, but maybe you like some of what i changed, here I leave it:
# do nothing if fzf is not installed((! $+commands[fzf] ))&&return# Bind for fzf history search((!${+ZSH_FZF_HISTORY_SEARCH_BIND}))&&typeset -g ZSH_FZF_HISTORY_SEARCH_BIND='^r'# Cursor to end-of-line((!${+ZSH_FZF_HISTORY_SEARCH_END_OF_LINE}))&&typeset -g ZSH_FZF_HISTORY_SEARCH_END_OF_LINE=''# Include event numbers((!${+ZSH_FZF_HISTORY_SEARCH_EVENT_NUMBERS}))&&typeset -g ZSH_FZF_HISTORY_SEARCH_EVENT_NUMBERS=1
# Include full date timestamps in ISO8601 `yyyy-mm-dd hh:mm' format((!${+ZSH_FZF_HISTORY_SEARCH_DATES_IN_SEARCH}))&&typeset -g ZSH_FZF_HISTORY_SEARCH_DATES_IN_SEARCH=1
# Remove duplicate entries in history((!${+ZSH_FZF_HISTORY_SEARCH_REMOVE_DUPLICATES}))&&typeset -g ZSH_FZF_HISTORY_SEARCH_REMOVE_DUPLICATES=''functionfzf_history_search() {
local cmd_col=1
local fc_args=
# SETUP DATESif [ -n"${ZSH_FZF_HISTORY_SEARCH_DATES_IN_SEARCH}" ];then
cmd_col=3
fc_args+=' -i'filocal his_out=$(fc ${=fc_args} -l 0)# REMOVE DUPLICATESif [ -n"${ZSH_FZF_HISTORY_SEARCH_REMOVE_DUPLICATES}" ];then
his_out=$(printf '%s\n'"$his_out"| sort -k $((cmd_col+1))| tac | uniq -f $((cmd_col))| sort)fi# REMOVE NUMBER COLUMNSif! [ -n"${ZSH_FZF_HISTORY_SEARCH_EVENT_NUMBERS}" ];then
his_out=$(printf '%s\n'"$his_out"| sed 's/^[[:blank:]]*[[:digit:]]*//')filocal e_num=$(printf '%s\n'"$his_out"| fzf --tac -q "$BUFFER"| awk '{print $1}')if [ -n"$e_num" ];then
BUFFER="!$e_num"
zle vi-fetch-history -n $BUFFER
zle expand-or-complete
if [ -n"$ZSH_FZF_HISTORY_SEARCH_END_OF_LINE" ];then
zle end-of-buffer-or-history
fifi#zle reset-prompt
}
autoload fzf_history_search
zle -N fzf_history_search
bindkey $ZSH_FZF_HISTORY_SEARCH_BIND fzf_history_search
The text was updated successfully, but these errors were encountered:
I managed to add support for multi-line blocks, and I want to share it.
What I did was to retrieve the number event of the selected command in fzf, and then use history expansion
zle expand-or-complete
with that number so zsh gets the correct block of code.I modified the script to my needs, didn't include some stuff, but maybe you like some of what i changed, here I leave it:
The text was updated successfully, but these errors were encountered: