-
-
Save Shougo/656148 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"============================================================================= | |
" FILE: everything.vim | |
" Last Modified: 28 Oct 2010 | |
" Description: everything のコマンドラインインタフェース(es.exe)を利用し、 | |
" NTFSボリュームの全てのファイルを瞬時にUniteから使うためのsource | |
" Requirement: everything.exe | |
" : es.exe in $PATH | |
"============================================================================= | |
function! unite#sources#everything#define()"{{{ | |
return s:source | |
endfunction"}}} | |
let s:available_vimproc = globpath(&runtimepath, 'autoload/vimproc.vim') != '' | |
let s:available_es = has('win32') && executable('es.exe') | |
let s:source = { | |
\ 'name' : 'everything', | |
\ 'is_volatile' : 1, | |
\} | |
function! s:source.gather_candidates(args, context)"{{{ | |
" Win32環境でなおかつ es.exe がなかったら空リストを返す | |
if !(s:available_es && s:available_vimproc && vimproc#version() >0) | |
return [] | |
endif | |
" 引数文字列がない場合 es.exe は全エントリを表示しようとするので却下 | |
if len(a:context.input) == 0 | |
return [] | |
endif | |
let l:input = substitute(a:context.input, '^\a\+:\zs\*/', '/', '') | |
" vimproc | |
let l:sub = vimproc#parser#popen2('es -n 50 -p ' . l:input) | |
let l:res = '' | |
while !l:sub.stdout.eof | |
let l:res .= l:sub.stdout.read() | |
endwhile | |
if &shellslash | |
let l:res = substitute(l:res, '\\', '/', 'g') | |
endif | |
let l:candidates = split(l:res, '\r\n\|\r\|\n') | |
let l:candidates_dir = [] | |
let l:candidates_file = [] | |
for l:entry in l:candidates | |
let l:dict = { 'word' : l:entry, 'abbr' : l:entry, 'source' : 'everything' } | |
if isdirectory(l:entry) | |
if l:entry !~ '^\%(/\|\a\+:/\)$' | |
let l:dict.abbr .= '/' | |
endif | |
let l:dict.kind = 'directory' | |
call add(l:candidates_dir, l:dict) | |
else | |
let l:dict.kind = 'file' | |
call add(l:candidates_file, l:dict) | |
endif | |
endfor | |
return l:candidates_dir + l:candidates_file | |
endfunction"}}} | |
" vim: foldmethod=marker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment