Last active
February 14, 2023 12:18
-
-
Save mwgkgk/ab4aeb151b9c1ec4dbf334c65da36244 to your computer and use it in GitHub Desktop.
Fuzzy find with per-directory frecency (using fd, fzf, fre)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awk '!x[$0]++'
trick is to avoidsort | uniq
, see https://stackoverflow.com/questions/11532157/remove-duplicate-lines-without-sorting