From 132234e74a9c167d844cbe406867cc5846e7a6a1 Mon Sep 17 00:00:00 2001 From: Patrick McFarland Date: Mon, 17 Jul 2023 15:08:06 -0400 Subject: [PATCH] Updated Examples (completion) (markdown) --- Examples-(completion).md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Examples-(completion).md b/Examples-(completion).md index aaabcbc..dbd0545 100644 --- a/Examples-(completion).md +++ b/Examples-(completion).md @@ -76,3 +76,18 @@ 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 ``` + +### [BASH] List files/dirs by smallest filesystem depth and by length + +A common user will typically attempt to complete a filename that isn't deep into their filesystem tree, nor of a long filename. Replacing the example given in the README with... + +```bash + _fzf_compgen_path() { + fd --hidden --follow --exclude ".git" . "$1" | awk '{ printf "%s\t%s\t%s\n", gsub("/", "/"), length, $0 }' | LC_ALL=C sort -n -t $'\t' -k1,2 | cut -f3- + } + + _fzf_compgen_dir() { + fd --type d --hidden --follow --exclude ".git" . "$1" | awk '{ printf "%s\t%s\t%s\n", gsub("/", "/"), length, $0 }' | LC_ALL=C sort -n -t $'\t' -k1,2 | cut -f3- + } +``` +... will bias fzf into giving more relevant results higher in the list with no performance implication. This has been tested on a moderately slow system (an 11 year old budget system with a SATA SSD), and with a testcase of 200k files it started displaying results in 0.7s. \ No newline at end of file