runtime(netrw): improve netrw's open-handling further

closes: #15956

Signed-off-by: Enno <Konfekt@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Enno
2024-10-28 20:47:25 +01:00
committed by Christian Brabandt
parent 7c96776729
commit 70197885a8

View File

@ -35,17 +35,18 @@ set cpo&vim
" Commands Launch/URL {{{2 " Commands Launch/URL {{{2
" surpress output of command; use bang for GUI applications " surpress output of command; use bang for GUI applications
" set up redirection (avoids browser messages) func s:redir()
" by default if not set, g:netrw_suppress_gx_mesg is true " set up redirection (avoids browser messages)
if get(g:, 'netrw_suppress_gx_mesg', 1) " by default if not set, g:netrw_suppress_gx_mesg is true
if &srr =~# "%s" if get(g:, 'netrw_suppress_gx_mesg', 1)
let s:redir = printf(&srr, has("win32") ? "nul" : "/dev/null") if &srr =~# "%s"
else return printf(&srr, has("win32") ? "nul" : "/dev/null")
let s:redir= &srr .. (has("win32") ? "nul" : "/dev/null") else
return &srr .. (has("win32") ? "nul" : "/dev/null")
endif
endif endif
else return ''
let s:redir= "" endfunc
endif
if has('unix') if has('unix')
if has('win32unix') if has('win32unix')
@ -60,26 +61,26 @@ if has('unix')
" Adding "" //b` sets void title, hides cmd window and blocks path conversion " Adding "" //b` sets void title, hides cmd window and blocks path conversion
" of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/ " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
command -complete=shellcmd -nargs=1 -bang Launch command -complete=shellcmd -nargs=1 -bang Launch
\ exe 'silent !start "" //b' trim(<q-args>) s:redir | redraw! \ exe 'silent !start "" //b' trim(<q-args>) s:redir() | redraw!
else else
" imitate /usr/bin/start script for other environments and hope for the best " imitate /usr/bin/start script for other environments and hope for the best
command -complete=shellcmd -nargs=1 -bang Launch command -complete=shellcmd -nargs=1 -bang Launch
\ exe 'silent !cmd //c start "" //b' trim(<q-args>) s:redir | redraw! \ exe 'silent !cmd //c start "" //b' trim(<q-args>) s:redir() | redraw!
endif endif
elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
command -complete=shellcmd -nargs=1 -bang Launch execute ':silent !'.. command -complete=shellcmd -nargs=1 -bang Launch execute ':silent !'..
\ ((<q-args> =~? '\v<\f+\.(exe|com|bat|cmd)>') ? \ ((<q-args> =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
\ 'cmd.exe /c start "" /b' trim(<q-args>) : \ 'cmd.exe /c start "" /b' trim(<q-args>) :
\ 'nohup ' trim(<q-args>) s:redir '&') \ 'nohup ' trim(<q-args>) s:redir() '&')
\ | redraw! \ | redraw!
else else
command -complete=shellcmd -nargs=1 -bang Launch command -complete=shellcmd -nargs=1 -bang Launch
\ exe ':silent ! nohup' trim(<q-args>) s:redir '&' | redraw! \ exe ':silent ! nohup' trim(<q-args>) s:redir() '&' | redraw!
endif endif
elseif has('win32') elseif has('win32')
command -complete=shellcmd -nargs=1 -bang Launch command -complete=shellcmd -nargs=1 -bang Launch
\ exe 'silent !'.. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c') \ exe 'silent !'.. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
\ 'start /b ' trim(<q-args>) s:redir | redraw! \ 'start /b ' trim(<q-args>) s:redir() | redraw!
endif endif
if exists(':Launch') == 2 if exists(':Launch') == 2
" Git Bash " Git Bash
@ -95,17 +96,15 @@ if exists(':Launch') == 2
" MacOS " MacOS
elseif executable('open') elseif executable('open')
let s:cmd = 'open' let s:cmd = 'open'
else
let s:cmd = ''
endif endif
function s:Open(cmd, file) function s:Open(file)
if empty(a:cmd) && !exists('g:netrw_browsex_viewer') if !exists('s:cmd') && !exists('g:netrw_browsex_viewer')
echoerr "No program to open this path found. See :help Open for more information." echoerr "No program to open this path found. See :help Open for more information."
else else
Launch cmd shellescape(a:file, 1) exe 'Launch' s:cmd shellescape(a:file, 1)
endif endif
endfunction endfunction
command -complete=file -nargs=1 Open call s:Open(s:cmd, <q-args>) command -complete=file -nargs=1 Open call s:Open(<q-args>)
endif endif
if !exists('g:netrw_regex_url') if !exists('g:netrw_regex_url')