| Crates.io | proximity-sort |
| lib.rs | proximity-sort |
| version | 1.3.0 |
| created_at | 2018-09-18 05:38:07.50755+00 |
| updated_at | 2023-02-11 20:11:56.076379+00 |
| description | Simple command-line utility for sorting inputs by proximity to a path argument |
| homepage | |
| repository | https://github.com/jonhoo/proximity-sort.git |
| max_upload_size | |
| id | 85314 |
| size | 40,782 |
This script provides a simple command-line utility that sorts its inputs
by their path proximity to a given path. For example, for a path
foo/bar.txt, the following input:
quox.txt
foo/bar.txt
foo/baz.txt
Would yield an output of:
foo/bar.txt
foo/baz.txt
quox.txt
The lines are sorted by the number of leading path components shared between the input path and the provided path.
This program was primarily written to allow context-aware suggestions
for fzf (requested in
junegunn/fzf.vim#360
and
junegunn/fzf.vim#492)
without making modifications to fzf itself (see
junegunn/fzf#1380).
If you have Rust installed, you can install this with:
cargo install proximity-sort
It can be used with fzf by running:
$ fd -t f | proximity-sort path/to/file | fzf --tiebreak=index
And you can add it to your .vimrc with:
function! s:list_cmd()
let base = fnamemodify(expand('%'), ':h:.:S')
return base == '.' ? 'fd -t f' : printf('fd -t f | proximity-sort %s', expand('%'))
endfunction
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, {'source': s:list_cmd(),
\ 'options': '--tiebreak=index'}, <bang>0)
Paths of the same proximity are sorted alphabetically:
$ echo "banana\napple/pie\napple" | proximity-sort . -s
> apple
> banana
> apple/pie