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

I'm removing this example, it'd be better to just use bfs instead of fd; this scriptlet won't early exit on pathologically slow filesystems (such as accessing filesystems mounted in Windows via WSL2 9P2000 bridges)

Patrick McFarland
2023-08-21 13:41:04 -04:00
parent 132234e74a
commit 27a9c4eac9

@@ -75,19 +75,4 @@ _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
```
### [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.
```