From ead8a827765386d046873c479b25fdae9174cf4a Mon Sep 17 00:00:00 2001 From: Patrick McFarland Date: Fri, 13 May 2022 18:55:32 -0400 Subject: [PATCH] Added "Path depth and hidden sorted _fzf_compgen_path/dir" --- Examples-(completion).md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Examples-(completion).md b/Examples-(completion).md index b2312ce..ff7f434 100644 --- a/Examples-(completion).md +++ b/Examples-(completion).md @@ -75,4 +75,40 @@ _fzf_complete_ssh_notrigger() { complete -o bashdefault -o default -F _fzf_complete_ssh_notrigger ssh complete -o bashdefault -o default -F _fzf_complete_ssh_notrigger mosh complete -o bashdefault -o default -F _fzf_complete_ssh_notrigger ss +``` + +### Path depth and hidden sorted _fzf_compgen_path/dir (feat. `fd` and `rg`) + +Based on the example in the [README](https://github.com/junegunn/fzf#settings) for `fd` integration, this sorts from least to greatest path depth and then sorts hidden files after regular ones. This puts the most likely files you're going to access further up in the list and gets them into `fzf` faster. + +```bash +_fzf_compgen_path() { + local output + local -i depth=1 + while + output=$(fd -H -L -E ".git" --exact-depth "$depth" . "$1") + + rg -v "^\.|/\." <<<"$output" + rg "^\.|/\." <<<"$output" + + depth+=1 + + [ "$output" ] + do true; done +} + +_fzf_compgen_dir() { + local output + local -i depth=1 + while + output=$(fd -H -L -E ".git" --exact-depth "$depth" -t d . "$1") + + rg -v "^\.|/\." <<<"$output" + rg "^\.|/\." <<<"$output" + + depth+=1 + + [ "$output" ] + do true; done +} ``` \ No newline at end of file