Skip to content

Instantly share code, notes, and snippets.

@mwgkgk
Last active February 14, 2023 12:18
Show Gist options
  • Save mwgkgk/ab4aeb151b9c1ec4dbf334c65da36244 to your computer and use it in GitHub Desktop.
Save mwgkgk/ab4aeb151b9c1ec4dbf334c65da36244 to your computer and use it in GitHub Desktop.
Fuzzy find with per-directory frecency (using fd, fzf, fre)
#!/bin/dash
set -o errexit
set -o nounset
fd_in=$PWD
fzf_height="--height 15"
if test $# -gt 0; then
for arg in "$@"; do
# -f for fullscreen
if test "$arg" = "-f"; then
fzf_height=""
else
# Latter args overwrite
fd_in=$arg
fi
done
fi
# Default store location is ~/.local/share/fre/
store_name=$(echo "dir:$fd_in" | md5sum | awk '{print $1}')
fzf_result=$({
fre --sorted --store_name "$store_name"
fd -t d --follow "" "$fd_in"
} | awk '!x[$0]++' | fzf +m --reverse $fzf_height --tiebreak=index)
if test -n "$fzf_result"; then
fre --add "$fzf_result" --store_name "$store_name" && echo "$fzf_result"
fi
@mwgkgk
Copy link
Author

mwgkgk commented Dec 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment