Replies: 2 comments 1 reply
-
fzf implements a modified Smith-Waterman algorithm. It's a sequence alignment algorithm that only allows gaps. https://github.com/junegunn/fzf/blob/tmux/src/algo/algo.go Tweaking weights or scoring is not going to help at all, because Like I mentioned in the #3791, you need a completely different algorithm for Having said that, fzf is a general-purpose text filter that is designed to be used with any type of input. Its CTRL-R implementation is basically a fuzzy, interactive version of |
Beta Was this translation helpful? Give feedback.
-
Lines 107 to 125 in 8a110e0 One idea could be to use a tool that tolerates typos and integrate it into a modified The changes involve saving the history to a temporary file and adding a Diff--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -107,10 +107,14 @@ fi
# CTRL-R - Paste the selected command from history into the command line
fzf-history-widget() {
- local selected num
- setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
- selected="$(fc -rl 1 | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' |
- FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m") \
- FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd))"
+ local selected num temp_file
+ temp_file=$(mktemp)
+ setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2>/dev/null
+ fc -rl 1 | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' >"$temp_file"
+ selected="$(FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --ansi --disabled \
+ --bind 'change:reload:agrep --color --max-errors 1 --regexp={q} -- $temp_file || :' \
+ --bind=ctrl-r:toggle-sort ${FZF_CTRL_R_OPTS-} --query=${LBUFFER} +m") \
+ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) <"$temp_file")"
local ret=$?
+ rm -f "$temp_file"
if [ -n "$selected" ]; then
num=$(awk '{print $1}' <<< "$selected") # install 'agrep' on macOS using Homebrew
brew install tre Customized history widget using # .zshrc
source <(fzf --zsh)
# CTRL-R - Paste the selected command from history into the command line
agrep-fzf-history-widget() {
local selected num temp_file
temp_file=$(mktemp)
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2>/dev/null
fc -rl 1 | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' >"$temp_file"
selected="$(FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --ansi --disabled \
--bind 'change:reload:agrep --color --max-errors 1 --regexp={q} -- $temp_file || :' \
--bind=ctrl-r:toggle-sort ${FZF_CTRL_R_OPTS-} --query=${LBUFFER} +m") \
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) <"$temp_file")"
local ret=$?
rm -f "$temp_file"
if [ -n "$selected" ]; then
num=$(awk '{print $1}' <<< "$selected")
if [[ "$num" =~ '^[1-9][0-9]*\*?$' ]]; then
zle vi-fetch-history -n ${num%\*}
else # selected is a custom query, not from history
LBUFFER="$selected"
fi
fi
zle reset-prompt
return $ret
}
zle -N agrep-fzf-history-widget
bindkey '^R' agrep-fzf-history-widget Note
Cool website comparing some fuzzy matching libraries: leeoniya.github.io/uFuzzy/demos/compare Footnotes |
Beta Was this translation helpful? Give feedback.
-
In a previous discussion #3791 (that also linked to a previous issue: #3648 (comment) ) it was clarified that fzf is actually not very tolerant of typos... (Im not really sure where the out of order typos comes in - whats an in order typo? etc.)
i thought, well it would be nice to somehow also weigh matches by their frequency in a file. IE: if I type wsudo I almost always mean a sudo command, which there are very many of them in my command history, as opposed to any w.*s.*u.*d.o. string...
I use zoxide for directory surfing and it maintains its own set of weights for directories.
If FZF could also somehow incorporate this, than asimple wraper around command history could be made to pass all history and weights to fzf.
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions