Skip to content

Commit

Permalink
[fzf#vim#with_preview] support wsl bash
Browse files Browse the repository at this point in the history
  • Loading branch information
janlazo committed May 13, 2020
1 parent a74605b commit 37d63d3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ if s:is_win
else
let s:bin.preview = fnamemodify(s:bin.preview, ':8')
endif
let s:bin.preview = 'bash '.escape(s:bin.preview, '\')
endif

let s:wide = 120
Expand Down Expand Up @@ -76,6 +75,11 @@ endfunction

" [[options to wrap], [preview window expression], [toggle-preview keys...]]
function! fzf#vim#with_preview(...)
let bash_path = exepath('bash')
if empty(bash_path)
throw 'bash is not in PATH'

This comment has been minimized.

Copy link
@habamax

habamax May 13, 2020

Does it break Files if bash is not installed? Wouldn't it be better to turn off preview if bash is not installed?

This comment has been minimized.

Copy link
@janlazo

janlazo May 13, 2020

Author Owner

Commands executed with a bang, !, are affected. :Files without the bang does not show the preview.

This comment has been minimized.

Copy link
@habamax

habamax May 13, 2020

sounds good, thx

endif
let is_wsl_bash = bash_path =~? 'Windows[/\\]system32[/\\]bash.exe$'
" Default options
let options = {}
let window = ''
Expand Down Expand Up @@ -104,7 +108,14 @@ function! fzf#vim#with_preview(...)
if len(window)
let preview += ['--preview-window', window]
endif
let preview += ['--preview', (s:is_win ? s:bin.preview : fzf#shellescape(s:bin.preview)).' '.placeholder]
if s:is_win
let preview_cmd = 'bash '.(is_wsl_bash
\ ? substitute(substitute(s:bin.preview, '^\([A-Z]\):\\', '/\L\1', ''), '\', '/', 'g')
\ : escape(s:bin.preview, '\'))
else
let preview_cmd = fzf#shellescape(s:bin.preview)
endif
let preview += ['--preview', preview_cmd.' '.placeholder]

if len(args)
call extend(preview, ['--bind', join(map(args, 'v:val.":toggle-preview"'), ',')])
Expand Down

0 comments on commit 37d63d3

Please sign in to comment.