0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

runtime(netrw): make :Launch/Open autoloadable

fixes: #15959
closes: #15962

Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Konfekt <Konfekt@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt 2024-10-31 09:21:23 +01:00
parent 9f32069b8c
commit 8b0fa7a565
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
4 changed files with 179 additions and 181 deletions

View File

@ -30,6 +30,7 @@
" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
" }}}
" Former Maintainer: Charles E Campbell
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
@ -1195,47 +1196,35 @@ fun! netrw#Lexplore(count,rightside,...)
" if a netrw window is already on the left-side of the tab
" and a directory has been specified, explore with that
" directory.
" call Decho("case has input argument(s) (a:1<".a:1.">)")
let a1 = expand(a:1)
" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
exe "1wincmd w"
if &ft == "netrw"
" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
exe "Explore ".fnameescape(a1)
exe curwin."wincmd w"
let s:lexplore_win= curwin
let w:lexplore_buf= bufnr("%")
if exists("t:netrw_lexposn")
" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
unlet t:netrw_lexposn
endif
" call Dret("netrw#Lexplore")
return
endif
exe curwin."wincmd w"
else
let a1= ""
" call Decho("no input arguments")
endif
if exists("t:netrw_lexbufnr")
" check if t:netrw_lexbufnr refers to a netrw window
let lexwinnr = bufwinnr(t:netrw_lexbufnr)
" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
else
let lexwinnr= 0
" call Decho("t:netrw_lexbufnr doesn't exist")
endif
" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
if lexwinnr > 0
" close down netrw explorer window
" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
exe lexwinnr."wincmd w"
let g:netrw_winsize = -winwidth(0)
let t:netrw_lexposn = winsaveview()
" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
close
if lexwinnr < curwin
let curwin= curwin - 1
@ -1244,11 +1233,9 @@ fun! netrw#Lexplore(count,rightside,...)
exe curwin."wincmd w"
endif
unlet t:netrw_lexbufnr
" call Decho("unlet t:netrw_lexbufnr")
else
" open netrw explorer window
" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
exe "1wincmd w"
let keep_altv = g:netrw_altv
let g:netrw_altv = 0
@ -1257,18 +1244,13 @@ fun! netrw#Lexplore(count,rightside,...)
let g:netrw_winsize = a:count
endif
let curfile= expand("%")
" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
" call Decho("new buf#".bufnr("%")." win#".winnr())
if a:0 > 0 && a1 != ""
" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
call netrw#Explore(0,0,0,a1)
exe "Explore ".fnameescape(a1)
elseif curfile =~ '^\a\{3,}://'
" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
else
" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
call netrw#Explore(0,0,0,".")
endif
if a:count != 0
@ -1281,11 +1263,7 @@ fun! netrw#Lexplore(count,rightside,...)
" Since the intended use of :Lexplore is to have an always-present explorer window, the extra
" effort to prevent mis-use of :Lex is warranted.
set bh=wipe
" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
if exists("t:netrw_lexposn")
" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
call winrestview(t:netrw_lexposn)
unlet t:netrw_lexposn
endif
@ -1298,10 +1276,8 @@ fun! netrw#Lexplore(count,rightside,...)
else
let g:netrw_chgwin= 2
endif
" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
endif
" call Dret("netrw#Lexplore")
endfun
" ---------------------------------------------------------------------
@ -5266,6 +5242,120 @@ fun! s:NetrwBrowseUpDir(islocal)
" call Dret("s:NetrwBrowseUpDir")
endfun
func s:redir()
" set up redirection (avoids browser messages)
" by default if not set, g:netrw_suppress_gx_mesg is true
if get(g:, 'netrw_suppress_gx_mesg', 1)
if &srr =~# "%s"
return printf(&srr, has("win32") ? "nul" : "/dev/null")
else
return &srr .. (has("win32") ? "nul" : "/dev/null")
endif
endif
return ''
endfunc
if has('unix')
if has('win32unix')
" Cygwin provides cygstart
if executable('cygstart')
fun! netrw#Launch(args)
exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
endfun
elseif !empty($MSYSTEM) && executable('start')
" MSYS2/Git Bash comes by default without cygstart; see
" https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
" Instead it provides /usr/bin/start script running `cmd.exe //c start`
" 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/
fun! netrw#Launch(args)
exe 'silent !start "" //b' a:args s:redir() | redraw!
endfun
else
" imitate /usr/bin/start script for other environments and hope for the best
fun! netrw#Launch(args)
exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
endfun
endif
elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
fun! netrw#Launch(args)
let args = a:args
exe 'silent !' ..
\ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
\ 'cmd.exe /c start "" /b ' .. args :
\ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
\ | redraw!
endfun
else
fun! netrw#Launch(args)
exe ':silent ! nohup' a:args s:redir() '&' | redraw!
endfun
endif
elseif has('win32')
fun! netrw#Launch(args)
exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
\ 'start "" /b' a:args s:redir() | redraw!
endfun
else
fun! netrw#Launch(dummy)
echom 'No common launcher found'
endfun
endif
" Git Bash
if has('win32unix')
" (cyg)start suffices
let s:os_viewer = ''
" Windows / WSL
elseif executable('explorer.exe')
let s:os_viewer = 'explorer.exe'
" Linux / BSD
elseif executable('xdg-open')
let s:os_viewer = 'xdg-open'
" MacOS
elseif executable('open')
let s:os_viewer = 'open'
endif
fun! s:viewer()
if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
" extract any viewing options. Assumes that they're set apart by spaces.
" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
if g:netrw_browsex_viewer =~ '\s'
let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
let oviewer = ''
let cnt = 1
while !executable(viewer) && viewer != oviewer
let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
let cnt = cnt + 1
let oviewer = viewer
" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
endwhile
else
let viewer = g:netrw_browsex_viewer
let viewopt = ""
endif
" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
return viewer .. ' ' .. viewopt
else
if !exists('s:os_viewer')
call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
else
return s:os_viewer
endif
endif
endfun
fun! netrw#Open(file) abort
call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
endf
if !exists('g:netrw_regex_url')
let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
endif
" ---------------------------------------------------------------------
" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
" given filename; typically this means given their extension.
@ -5349,31 +5439,8 @@ fun! netrw#BrowseX(fname,remote)
endif
endif
" extract any viewing options. Assumes that they're set apart by spaces.
if exists("g:netrw_browsex_viewer")
if g:netrw_browsex_viewer =~ '\s'
let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
let oviewer = ''
let cnt = 1
while !executable(viewer) && viewer != oviewer
let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
let cnt = cnt + 1
let oviewer = viewer
endwhile
else
let viewer = g:netrw_browsex_viewer
let viewopt = ""
endif
endif
if exists("g:netrw_browsex_viewer") && executable(viewer)
exe 'Launch' viewer viewopt shellescape(fname, 1)
else
" though shellescape(..., 1) is used in Open, it's insufficient
exe 'Open' escape(fname, '#%')
endif
" although shellescape(..., 1) is used in netrw#Open(), it's insufficient
call netrw#Open(escape(fname, '#%'))
" cleanup: remove temporary file,
" delete current buffer if success with handler,
@ -5665,7 +5732,7 @@ fun! s:NetrwGlob(direntry,expr,pare)
endif
let w:netrw_liststyle= keep_liststyle
else
let path= s:ComposePath(fnameescape(a:direntry),a:expr)
let path= s:ComposePath(fnameescape(a:direntry), a:expr)
if has("win32")
" escape [ so it is not detected as wildcard character, see :h wildcard
let path= substitute(path, '[', '[[]', 'g')
@ -5679,7 +5746,6 @@ fun! s:NetrwGlob(direntry,expr,pare)
let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
endif
endif
" call Dret("s:NetrwGlob ".string(filelist))
return filelist
endfun
@ -8212,7 +8278,7 @@ fun! netrw#Shrink()
elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
exe "vert resize ".t:netrw_winwidth
" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
else
else
call netrw#Lexplore(0,0)
endif
@ -8529,7 +8595,7 @@ fun! s:NetrwPrevWinOpen(islocal)
" call Decho("COMBAK#11: mod=".&mod)
" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
" call Decho("COMBAK#12: mod=".&mod)
if exists("s:lexplore_win") && s:lexplore_win == winnr()
" whoops -- user trying to open file in the Lexplore window.
" Use Lexplore's opening-file window instead.
@ -11944,7 +12010,7 @@ fun! s:NetrwEnew(...)
" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
" Clean out the last buffer:
" Clean out the last buffer:
" Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
" If so, delete it.
call s:NetrwBufRemover(bufnr("$"))
@ -12136,7 +12202,7 @@ fun! s:NetrwHumanReadable(sz)
" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
if g:netrw_sizestyle == 'h'
if a:sz >= 1000000000
if a:sz >= 1000000000
let sz = printf("%.1f",a:sz/1000000000.0)."g"
elseif a:sz >= 10000000
let sz = printf("%d",a:sz/1000000)."m"
@ -12564,7 +12630,7 @@ endfun
fun! s:ShellEscape(s, ...)
if has('win32') && $SHELL == '' && &shellslash
return printf('"%s"', substitute(a:s, '"', '""', 'g'))
endif
endif
let f = a:0 > 0 ? a:1 : 0
return shellescape(a:s, f)
endfun

View File

@ -1,4 +1,4 @@
*pi_netrw.txt* For Vim version 9.1. Last change: 2024 Oct 27
*pi_netrw.txt* For Vim version 9.1. Last change: 2024 Oct 31
------------------------------------------------
NETRW REFERENCE MANUAL by Charles E. Campbell
@ -1469,7 +1469,6 @@ With either form of the command, netrw will first ask for confirmation
that the removal is in fact what you want to do. If netrw doesn't have
permission to remove a file, it will issue an error message.
*netrw-gx* *Open* *Launch*
CUSTOMIZING BROWSING WITH A SPECIAL HANDLER *netrw-x* *netrw-handler* {{{2
Certain files, such as html, gif, jpeg, (word/office) doc, etc, files, are
@ -1479,7 +1478,7 @@ operating system). Netrw allows one to invoke such special handlers by:
* hitting gx with the cursor atop the file path or alternatively x
in a netrw buffer; the former can be disabled by defining the
|g:netrw_nogx| variable
* when in command line, typing :Open <path>
* when in command line, typing :Open <path>, see |:Open| below.
One may also use visual mode (see |visual-start|) to select the text that the
special handler will use. Normally gx checks for a close-by URL or file name
@ -1490,47 +1489,54 @@ select the text to be used by gx by making a visual selection (see
|visual-block|) and then pressing gx.
The selection function can be adapted for each filetype by adding a function
Netrw_get_URL_<filetype>, where <filetype> is given by &filetype.
`Netrw_get_URL_<filetype>`, where <filetype> is given by the 'filetype'.
The function should return the URL or file name to be used by gx, and will
fall back to the default behavior if it returns an empty string.
For example, special handlers for links Markdown and HTML are
>
" make gx work on concealed links regardless of exact cursor position
function Netrw_get_URL_markdown()
" markdown URL such as [link text](http://ya.ru 'yandex search')
try
let save_view = winsaveview()
if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0
return matchstr(getline('.')[col('.')-1:], '\[.\{-}\](\zs' .. g:netrw_regex_url .. '\ze\(\s\+.\{-}\)\?)')
endif
finally
call winrestview(save_view)
return ''
endtry
endfunction
function Netrw_get_URL_html()
" HTML URL such as <a href='http://www.python.org'>Python is here</a>
" <a href="http://www.python.org"/>
try
let save_view = winsaveview()
if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0
return matchstr(getline('.')[col('.') - 1 : ],
\ 'href=["'.."'"..']\?\zs\S\{-}\ze["'.."'"..']\?/\?>')
endif
finally
call winrestview(save_view)
return ''
endtry
endfunction
" make gx work on concealed links regardless of exact cursor position: >
function Netrw_get_URL_markdown()
" markdown URL such as [link text](http://ya.ru 'yandex search')
try
let save_view = winsaveview()
if searchpair('\[.\{-}\](', '', ')\zs', 'cbW', '', line('.')) > 0
return matchstr(getline('.')[col('.')-1:],
\ '\[.\{-}\](\zs' .. g:netrw_regex_url .. '\ze\(\s\+.\{-}\)\?)')
endif
finally
call winrestview(save_view)
return ''
endtry
endfunction
function Netrw_get_URL_html()
" HTML URL such as <a href='http://www.python.org'>Python is here</a>
" <a href="http://www.python.org"/>
try
let save_view = winsaveview()
if searchpair('<a\s\+href=', '', '\%(</a>\|/>\)\zs', 'cbW', '', line('.')) > 0
return matchstr(getline('.')[col('.') - 1 : ],
\ 'href=["'.."'"..']\?\zs\S\{-}\ze["'.."'"..']\?/\?>')
endif
finally
call winrestview(save_view)
return ''
endtry
endfunction
<
Other than a file path, the text under the cursor may be a URL. Netrw uses
by default the following regular expression to determine if the text under the
cursor is a URL:
>
g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
:let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
<
Associated setting variables:
|g:netrw_gx| control how gx picks up the text under the cursor
|g:netrw_nogx| prevent gx map while editing
|g:netrw_suppress_gx_mesg| controls gx's suppression of browser messages
OPENING FILES AND LAUNCHING APPS *netrw-gx* *:Open* *:Launch* {{{2
Netrw determines which special handler by the following method:
@ -1544,24 +1550,25 @@ Netrw determines which special handler by the following method:
* for Mac OS X : open is used.
* for Linux : xdg-open is used.
To open a file <filepath> by the appropriate handler, type
To open a path (or URL) <path> by the appropriate handler, type >
:Open <filepath>
:Open <path>
<
No escaping, neither for the shell nor for Vim's command-line, is needed.
No escaping, neither for the shell, nor for Vim's command-line is needed.
To launch a specific application <app> <args>, often <args> being <path> >
To launch a specific application <app> <args>, often <args> being <filepath>,
:Launch <app> <args>.
:Launch <app> <args>.
Since <args> can be arbitrarily complex, in particular contain many file
paths, the escaping is left to the user.
Associated setting variables:
|g:netrw_gx| control how gx picks up the text under the cursor
|g:netrw_nogx| prevent gx map while editing
|g:netrw_suppress_gx_mesg| controls gx's suppression of browser messages
If you disabled the netrw plugin by setting g:loaded_netrwPlugin (see
|netrw-noload|), then you can use >
:call netrw#Launch('<app> <args>')
:call netrw#Open('<path>')
<
*netrw-curdir*
DELETING BOOKMARKS *netrw-mB* {{{2

View File

@ -2129,6 +2129,7 @@ $quote eval.txt /*$quote*
:LP pi_logipat.txt /*:LP*
:LPE pi_logipat.txt /*:LPE*
:LPF pi_logipat.txt /*:LPF*
:Launch pi_netrw.txt /*:Launch*
:Lexplore pi_netrw.txt /*:Lexplore*
:Lfilter quickfix.txt /*:Lfilter*
:LogiPat pi_logipat.txt /*:LogiPat*
@ -2146,6 +2147,7 @@ $quote eval.txt /*$quote*
:Ntree pi_netrw.txt /*:Ntree*
:Nw pi_netrw.txt /*:Nw*
:Nwrite pi_netrw.txt /*:Nwrite*
:Open pi_netrw.txt /*:Open*
:Over terminal.txt /*:Over*
:P various.txt /*:P*
:Pexplore pi_netrw.txt /*:Pexplore*
@ -5566,7 +5568,6 @@ KeyInputPre autocmd.txt /*KeyInputPre*
Kibaale uganda.txt /*Kibaale*
Korean mbyte.txt /*Korean*
L motion.txt /*L*
Launch pi_netrw.txt /*Launch*
Linux-backspace options.txt /*Linux-backspace*
List eval.txt /*List*
Lists eval.txt /*Lists*
@ -5622,7 +5623,6 @@ OS390-open-source os_390.txt /*OS390-open-source*
Object vim9class.txt /*Object*
OffTheSpot mbyte.txt /*OffTheSpot*
OnTheSpot mbyte.txt /*OnTheSpot*
Open pi_netrw.txt /*Open*
Operator-pending intro.txt /*Operator-pending*
Operator-pending-mode intro.txt /*Operator-pending-mode*
OptionSet autocmd.txt /*OptionSet*

View File

@ -6,6 +6,7 @@
" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
" 2024 Oct 27 by Vim Project: cleanup gx mapping
" 2024 Oct 28 by Vim Project: further improvements
" 2024 Oct 31 by Vim Project: use autoloaded functions
" Former Maintainer: Charles E Campbell
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
" Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1
@ -34,84 +35,8 @@ set cpo&vim
" Public Interface: {{{1
" Commands Launch/URL {{{2
" surpress output of command; use bang for GUI applications
func s:redir()
" set up redirection (avoids browser messages)
" by default if not set, g:netrw_suppress_gx_mesg is true
if get(g:, 'netrw_suppress_gx_mesg', 1)
if &srr =~# "%s"
return printf(&srr, has("win32") ? "nul" : "/dev/null")
else
return &srr .. (has("win32") ? "nul" : "/dev/null")
endif
endif
return ''
endfunc
if has('unix')
if has('win32unix')
" If cygstart provided, then assume Cygwin and use cygstart --hide; see man cygstart.
if executable('cygstart')
command -complete=shellcmd -nargs=1 -bang Launch
\ exe 'silent ! cygstart --hide' trim(<q-args>) s:redir() | redraw!
elseif !empty($MSYSTEM) && executable('start')
" MSYS2/Git Bash comes by default without cygstart; see
" https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
" Instead it provides /usr/bin/start script running `cmd.exe //c start`
" 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/
command -complete=shellcmd -nargs=1 -bang Launch
\ exe 'silent !start "" //b' trim(<q-args>) s:redir() | redraw!
else
" imitate /usr/bin/start script for other environments and hope for the best
command -complete=shellcmd -nargs=1 -bang Launch
\ exe 'silent !cmd //c start "" //b' trim(<q-args>) s:redir() | redraw!
endif
elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
command -complete=shellcmd -nargs=1 -bang Launch execute ':silent !'..
\ ((<q-args> =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
\ 'cmd.exe /c start "" /b' trim(<q-args>) :
\ 'nohup ' trim(<q-args>) s:redir() '&')
\ | redraw!
else
command -complete=shellcmd -nargs=1 -bang Launch
\ exe ':silent ! nohup' trim(<q-args>) s:redir() '&' | redraw!
endif
elseif has('win32')
command -complete=shellcmd -nargs=1 -bang Launch
\ exe 'silent !'.. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
\ 'start /b ' trim(<q-args>) s:redir() | redraw!
endif
if exists(':Launch') == 2
" Git Bash
if has('win32unix')
" start suffices
let s:cmd = ''
" Windows / WSL
elseif executable('explorer.exe')
let s:cmd = 'explorer.exe'
" Linux / BSD
elseif executable('xdg-open')
let s:cmd = 'xdg-open'
" MacOS
elseif executable('open')
let s:cmd = 'open'
endif
function s:Open(file)
if !exists('s:cmd') && !exists('g:netrw_browsex_viewer')
echoerr "No program to open this path found. See :help Open for more information."
else
exe 'Launch' s:cmd shellescape(a:file, 1)
endif
endfunction
command -complete=file -nargs=1 Open call s:Open(<q-args>)
endif
if !exists('g:netrw_regex_url')
let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
endif
command -complete=shellcmd -nargs=1 Launch call netrw#Launch(trim(<q-args>))
command -complete=file -nargs=1 Open call netrw#Open(trim(<q-args>))
" " }}}
" Local Browsing Autocmds: {{{2
augroup FileExplorer