Commit 52cfee8c authored by Marco Kellershoff's avatar Marco Kellershoff 🤸

Check if it's a valid URL, otherwise (optional) fallback to investigate.vim

parent 912ba389
......@@ -12,6 +12,9 @@ Here's a quick example:
```vim
" OpenUrl.nvim binding
nnoremap <leader>e :call OpenUrl#UnderCursor()<CR>
nnoremap <leader>q :call OpenUrl#UnderCursor()<CR>
" Use keith/investigate.vim as a fallback, if it's not an URL
let g:loaded_OpenUrl_DarkInvestigate = 1
```
......@@ -5,17 +5,24 @@ let g:loaded_OpenUrl = 1
function! OpenUrl#UnderCursor()
let s:url = OpenUrl#GetWordUnderCursor()
if has('win16') || has('win32') || has('win64')
exe '!start cmd /cstart /b '.s:url.''
elseif has('mac') || has('macunix') || has('gui_macvim')
exe 'silent !open "'.s:url.'"'
let s:is_url = OpenUrl#IsUrl(s:url)
if s:is_url == 1
call OpenUrl#WithDefaultBrowser(s:url)
else
exe 'silent !xdg-open "'.s:url.'"'
call OpenUrl#PassToDarkInvestigate()
endif
endfunction
function! OpenUrl#PassToDarkInvestigate()
let s:url = OpenUrl#GetWordUnderCursor()
if exists('g:loaded_OpenUrl_DarkInvestigate')
call investigate#Investigate()
else
echo 'No valid URL found: '.s:url
endif
redraw!
endfunction
function! OpenUrl#Open(url)
function! OpenUrl#WithDefaultBrowser(url)
if has('win16') || has('win32') || has('win64')
exe '!start cmd /cstart /b '.a:url.''
elseif has('mac') || has('macunix') || has('gui_macvim')
......@@ -36,6 +43,15 @@ function! OpenUrl#OpenWith(app, file)
endif
endfunction
function! OpenUrl#IsUrl(str)
let s:url = matchstr(a:str, '[a-z]*:\/\/[^ >,;]*')
if empty(s:url)
return 0
else
return 1
endif
endfunction
function! OpenUrl#GetWordUnderCursor()
return expand("<cWORD>")
endfunction
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment