m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-18 00:03:39 -05:00

Updated Examples (completion) (markdown)

Patrick McFarland
2023-07-17 15:08:06 -04:00
parent aa96f468b8
commit 132234e74a

@@ -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.