summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-02-12 18:01:41 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-02-12 18:01:41 +0900
commit9d7480ae3c109358ea0979626c6c9f68c79111c8 (patch)
tree429fe16fa6017521f6f24f27c4c5ef09c857d89e /plugin
parentf39cf6d855ace3a38efb4fd0f11f792a53319992 (diff)
[vim] Use install.ps1 to download binary on Windows
Credits to @jiangjianshan
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim45
1 files changed, 32 insertions, 13 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index b024c92a..62671b12 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -119,30 +119,49 @@ let s:default_layout = { 'down': '~40%' }
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
let s:fzf_go = s:base_dir.'/bin/fzf'
let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'
-let s:install = s:base_dir.'/install'
let s:installed = 0
let s:cpo_save = &cpo
set cpo&vim
+function! s:download_bin()
+ if s:installed
+ return 0
+ endif
+
+ if s:is_win && !has('win32unix')
+ let script = s:base_dir.'/install.ps1'
+ if !filereadable(script)
+ return 0
+ endif
+ let script = 'powershell -ExecutionPolicy Bypass -file ' . script
+ else
+ let script = s:base_dir.'/install'
+ if !executable(script)
+ return 0
+ endif
+ let script .= ' --bin'
+ endif
+
+ if input('fzf executable not found. Download binary? (y/n) ') !~? '^y'
+ return 0
+ end
+
+ redraw
+ echo
+ call s:warn('Downloading fzf binary. Please wait ...')
+ let s:installed = 1
+ call system(script)
+ return v:shell_error == 0
+endfunction
+
function! s:fzf_exec()
if !exists('s:exec')
if executable(s:fzf_go)
let s:exec = s:fzf_go
elseif executable('fzf')
let s:exec = 'fzf'
- elseif s:is_win && !has('win32unix')
- call s:warn('fzf executable not found.')
- call s:warn('Download fzf binary for Windows from https://github.com/junegunn/fzf-bin/releases/')
- call s:warn('and place it as '.s:base_dir.'\bin\fzf.exe')
- throw 'fzf executable not found'
- elseif !s:installed && executable(s:install) &&
- \ input('fzf executable not found. Download binary? (y/n) ') =~? '^y'
- redraw
- echo
- call s:warn('Downloading fzf binary. Please wait ...')
- let s:installed = 1
- call system(s:install.' --bin')
+ elseif s:download_bin()
return s:fzf_exec()
else
redraw