summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2014-03-25 12:05:51 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2014-03-25 12:05:57 +0900
commitb8e438b6be91b2e0259a8d122e64e32377a0efca (patch)
treee4e4b4d23ec5a80b652bb461bebddd14f0696692
parent678e950b6dcb786473bf5c5e0d097cfc1e6bfbfa (diff)
Prefer pre-existing function/alias in Vim plugin
-rw-r--r--plugin/fzf.vim16
1 files changed, 13 insertions, 3 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 0a18d22e..43e73d70 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -21,7 +21,18 @@
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-let s:exec = expand('<sfile>:h:h').'/fzf'
+call system('type fzf')
+if v:shell_error
+ let s:fzf_rb = expand('<sfile>:h:h').'/fzf'
+ if executable(s:fzf_rb)
+ let s:exec = s:fzf_rb
+ else
+ echoerr 'fzf executable not found'
+ finish
+ endif
+else
+ let s:exec = 'fzf'
+endif
function! s:escape(path)
return substitute(a:path, ' ', '\\ ', 'g')
@@ -38,9 +49,8 @@ function! fzf#run(command, ...)
let argstr = join(args)
let tf = tempname()
let prefix = exists('g:fzf_source') ? g:fzf_source.'|' : ''
- let fzf = executable(s:exec) ? s:exec : 'fzf'
let options = empty(argstr) ? get(g:, 'fzf_options', '') : argstr
- execute "silent !".prefix.fzf.' '.options." > ".tf
+ execute 'silent !'.prefix.s:exec.' '.options.' > '.tf
if !v:shell_error
for line in readfile(tf)
if !empty(line)