Skip to content
Myr

[vim] Compare binary versions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Close #2410

authored by Junegunn Choi · committed by Junegunn Choi · parent 977e5ef · Browse files · 1 file+58 added−25 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+58 added−25 removed

  • other:+58 added−25 removed

1 file+58 added−25 removed

modified:plugin/fzf.vim+58 added-25 removed
152 unmodified lines
153 throw 'Failed to download fzf: '.script154 endif155endfunction156157function! s:version_requirement(val, min)158 let val = split(a:val, '\.')159 let min = split(a:min, '\.')160 for idx in range(0, len(min) - 1)161 let v = get(val, idx, 0)162 if v < min[idx] | return 0163 elseif v > min[idx] | return 1157let s:versions = {}158function s:get_version(bin)159 if has_key(s:versions, a:bin)160 return s:versions[a:bin]161 end162 let command = a:bin . ' --version'163 let output = systemlist(command)164 if v:shell_error || empty(output)165 return ''166 endif167 let ver = matchstr(output[-1], '[0-9.]\+')168 let s:versions[a:bin] = ver169 return ver170endfunction171172function! s:compare_versions(a, b)173 let a = split(a:a, '\.')174 let b = split(a:b, '\.')175 for idx in range(0, max([len(a), len(b)]) - 1)176 let v1 = str2nr(get(a, idx, 0))177 let v2 = str2nr(get(b, idx, 0))178 if v1 < v2 | return -1179 elseif v1 > v2 | return 1180 endif181 endfor166 return 1182 return 0183endfunction184185function! s:compare_binary_versions(a, b)186 return s:compare_versions(s:get_version(a:a), s:get_version(a:b))187endfunction188189let s:checked = {}190function! fzf#exec(...)191 if !exists('s:exec')192 let binaries = []193 if executable('fzf')194 call add(binaries, 'fzf')195 endif196 if executable(s:fzf_go)173 let s:exec = s:fzf_go174 elseif executable('fzf')175 let s:exec = 'fzf'176 elseif input('fzf executable not found. Download binary? (y/n) ') =~? '^y'177 redraw178 call fzf#install()179 return fzf#exec()180 else181 redraw182 throw 'fzf executable not found'197 call add(binaries, s:fzf_go)198 endif199200 if empty(binaries)201 if input('fzf executable not found. Download binary? (y/n) ') =~? '^y'202 redraw203 call fzf#install()204 return fzf#exec()205 else206 redraw207 throw 'fzf executable not found'208 endif209 elseif len(binaries) > 1210 call sort(binaries, 's:compare_binary_versions')211 endif212213 let s:exec = binaries[-1]214 endif215216 if a:0 && !has_key(s:checked, a:1)187 let command = s:exec . ' --version'188 let output = systemlist(command)189 if v:shell_error || empty(output)190 throw printf('Failed to run "%s": %s', command, output)191 endif192 let fzf_version = matchstr(output[-1], '[0-9.]\+')193 if s:version_requirement(fzf_version, a:1)217 let fzf_version = s:get_version(s:exec)218 if empty(fzf_version)219 let message = printf('Failed to run "%s --version"', s:exec)220 unlet s:exec221 throw message222 end223224 if s:compare_versions(fzf_version, a:1) >= 0225 let s:checked[a:1] = 1226 return s:exec227 elseif a:0 < 2 && input(printf('You need fzf %s or above. Found: %s. Download binary? (y/n) ', a:1, fzf_version)) =~? '^y'228 let s:versions = {}229 unlet s:exec230 redraw231 call fzf#install()232 return fzf#exec(a:1, 1)233 else
794 unmodified lines