|
function! s:get_browser_command()
let vs_play_browser_command = get(g:, 'vs_play_browser_command', '')
if vs_play_browser_command == ''
if IsWin()
let vs_play_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%'
elseif has('mac') || has('maxunix') || has('gui_macvim') || system('uname') =~? '^darwin'
let vs_play_browser_command = 'open %URL%'
elseif executable('xdg-open')
let vs_play_browser_command = 'xdg-open %URL%'
elseif executable('firefox')
let vs_play_browser_command = 'firefox %URL%'
else
let vs_play_browser_command = ''
endif
endif
return vs_play_browser_command
endfunction
function! vs#OpenBrowser(url)
let cmd = s:get_browser_command()
if len(cmd) == 0
redraw
echohl WarningMsg
echo "No browser detected. Please open the URL below."
echohl None
echo a:url
return
endif
if cmd =~ '^!'
let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g')
silent! exec cmd
elseif cmd =~ '^:[A-Z]'
let cmd = substitute(cmd, '%URL%', '\=a:url', 'g')
exec cmd
else
let cmd = substitute(cmd, '%URL%', '\=shellescape(a:url)', 'g')
call system(cmd)
endif
endfunction
" vim:ts=4:sw=4:et
|