Skip to content

Instantly share code, notes, and snippets.

@isaec
Last active March 7, 2024 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaec/ebed80db75d826a77fd528e955db8670 to your computer and use it in GitHub Desktop.
Save isaec/ebed80db75d826a77fd528e955db8670 to your computer and use it in GitHub Desktop.
find nearby words to your primary selection area using levenshtein, then fuzzy filter if needed, and write the choice to the clipboard
function near
set selection (
cat /usr/share/dict/american-english \
| similar-sort -- (xclip -o) \
# tiebreak=index to prefer LD sort order
| fzf -i +m --tiebreak=index --preview "dict {}" --preview-window="right,80%,wrap,<60(wrap,up,45%)"
)
# only run xclip if something was selected (i.e. not if fzf was exited)
if test "$status" -eq 0
# using -loops 2 to wait until clipboard manager has grabbed
# using -quiet puts xclip in foreground so we wait to exit
echo "$selection" | xclip -r -sel clip -loops 2 -quiet
end
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment