Add an option to remove event numbers from search
Event numbers don't add information to the search: if you knew the event number you wouldn't be searching for the command. Add an option to remove them from the search to declutter it. Default it to true to preserve the current behaviour.
This commit is contained in:
@@ -17,12 +17,25 @@ typeset -g ZSH_FZF_HISTORY_SEARCH_FZF_EXTRA_ARGS=''
|
||||
(( ! ${+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
|
||||
|
||||
fzf_history_search() {
|
||||
setopt extendedglob
|
||||
candidates=(${(f)"$(fc -li -1 0 | fzf ${=ZSH_FZF_HISTORY_SEARCH_FZF_ARGS} ${=ZSH_FZF_HISTORY_SEARCH_FZF_EXTRA_ARGS} -q "$BUFFER")"})
|
||||
|
||||
FC_ARGS="-li"
|
||||
CANDIDATE_LEADING_FIELDS=4
|
||||
|
||||
if (( ! $ZSH_FZF_HISTORY_SEARCH_EVENT_NUMBERS )); then
|
||||
FC_ARGS+=" -n"
|
||||
CANDIDATE_LEADING_FIELDS=3
|
||||
fi
|
||||
|
||||
candidates=(${(f)"$(fc ${=FC_ARGS} -1 0 | fzf ${=ZSH_FZF_HISTORY_SEARCH_FZF_ARGS} ${=ZSH_FZF_HISTORY_SEARCH_FZF_EXTRA_ARGS} -q "$BUFFER")"})
|
||||
local ret=$?
|
||||
if [ -n "$candidates" ]; then
|
||||
BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[4,-1]}}"
|
||||
BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[${CANDIDATE_LEADING_FIELDS},-1]}}"
|
||||
BUFFER="${BUFFER[@]/(#b)(?)\\n/$match[1]
|
||||
}"
|
||||
zle vi-fetch-history -n $BUFFER
|
||||
|
||||
Reference in New Issue
Block a user