From bd7213774639f12d7c6ad273d1fe8f9c7df5ea68 Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Fri, 12 Feb 2016 08:58:05 +0000 Subject: [PATCH] Use Pick differently --- git/gitignore.symlink | 2 ++ vim/vimrc.symlink | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/git/gitignore.symlink b/git/gitignore.symlink index 9ba24b2..34acd7e 100644 --- a/git/gitignore.symlink +++ b/git/gitignore.symlink @@ -16,3 +16,5 @@ GoToFile .idea + +.pick_index diff --git a/vim/vimrc.symlink b/vim/vimrc.symlink index 143a934..cef71df 100644 --- a/vim/vimrc.symlink +++ b/vim/vimrc.symlink @@ -66,9 +66,63 @@ set shell=bash " My fuzzy file finder has changed, but the commands I use to interact " with it have not. These have the advantage of being close together on " my keyboard, as well as vaguely mnemonic. + +let g:pick_executable = "pick" +let g:pick_index_file = ".pick_index" + +function! PickCommand(choice_command, pick_args, vim_command) + try + let selection = system(a:choice_command . " | " . g:pick_executable . " " . a:pick_args) + redraw! + if v:shell_error == 0 + try + exec a:vim_command . " " . selection + catch /E325/ + endtry + endif + catch /Vim:Interrupt/ + " Swallow the ^C so that the redraw below happens; otherwise there will be + " leftovers from pick on the screen + redraw! + endtry +endfunction + +function! s:FileListCommand() + if filereadable(g:pick_index_file) == 0 + call system("find * -type f -o -type l > " . g:pick_index_file) + endif + + let l:choice_command = "cat " . g:pick_index_file + + return l:choice_command +endfunction + +function! s:BufferListCommand() + let bufnrs = filter(range(1, bufnr("$")), 'buflisted(v:val)') + let buffers = map(bufnrs, 'bufname(v:val)') + return 'echo "' . join(buffers, "\n") . '"' +endfunction + +function! PickBuffer() + call PickCommand(s:BufferListCommand(), "", ":buffer") +endfunction + +function! PickFile() + call PickCommand(s:FileListCommand(), "", ":edit") +endfunction + +function! PickFileVerticalSplit() + call PickCommand(s:FileListCommand(), "", ":vsplit") +endfunction + +function! RefreshPickIndex() + call system("rm " . g:pick_index_file) +endfunction + nnoremap t :call PickFile() nnoremap b :call PickBuffer() nnoremap n :call PickFileVerticalSplit() +nnoremap :call RefreshPickIndex() " Git blame "