proximity-sort 1.0.4

Simple command-line utility for sorting inputs by proximity to a path argument
proximity-sort-1.0.4 is not a library.

proximity-sort Build Status

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:


Would yield an output of:


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

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('%'))

command! -bang -nargs=? -complete=dir Files
  \ call fzf#vim#files(<q-args>, {'source': s:list_cmd(),
  \                               'options': '--tiebreak=index'}, <bang>0)