diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-10-31 18:54:53 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2024-10-31 18:55:08 +0800 |
commit | c1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d (patch) | |
tree | c5e847010b83c200a6594fcc94261ddb6e25385e /runtime/plugin/netrwPlugin.vim | |
parent | 0a1eeb90cb9a71c0790be2963c8ea054f2b1651b (diff) | |
download | rneovim-c1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d.tar.gz rneovim-c1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d.tar.bz2 rneovim-c1e020b7f3457d3a14e7dda72a4f6ebf06e8f91d.zip |
vim-patch:3d7e567: runtime(netrw): simplify gx file handling
It did not work very well, at least on Debian 12, and I am not sure Git
Bash and WSL, for example, were taken care of as maintenance stalled.
The whole logic was somewhat convoluted with some parts repeatedly invoking
failed commands.
The file handling was outdated, for example, nowadays Netscape is rarely
used, and also opinionated, for example mainly Microsoft Paint and Gimp for
Image files.
Instead, let's use (xdg-)open and similar commands on other systems
which respects the user's preferences.
closes: vim/vim#15721
https://github.com/vim/vim/commit/3d7e567ea7392e43a90a6ffb3cd49b71a7b59d1a
Co-authored-by: Konfekt <Konfekt@users.noreply.github.com>
Co-authored-by: Luca Saccarola <96259932+saccarosium@users.noreply.github.com>
Diffstat (limited to 'runtime/plugin/netrwPlugin.vim')
-rw-r--r-- | runtime/plugin/netrwPlugin.vim | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/runtime/plugin/netrwPlugin.vim b/runtime/plugin/netrwPlugin.vim index c70e6518ff..59fb7e727e 100644 --- a/runtime/plugin/netrwPlugin.vim +++ b/runtime/plugin/netrwPlugin.vim @@ -1,9 +1,10 @@ " netrwPlugin.vim: Handles file transfer and remote directory listing across a network " PLUGIN SECTION " Maintainer: This runtime file is looking for a new maintainer. -" Date: Feb 09, 2021 +" Date: Sep 09, 2021 " Last Change: " 2024 May 08 by Vim Project: cleanup legacy Win9X checks +" 2024 Oct 27 by Vim Project: cleanup gx mapping " Former Maintainer: Charles E Campbell " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim " Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1 @@ -31,6 +32,87 @@ set cpo&vim " --------------------------------------------------------------------- " Public Interface: {{{1 +" Commands Launch/URL {{{2 +" surpress output of command; use bang for GUI applications + +" set up redirection (avoids browser messages) +" by default, g:netrw_suppress_gx_mesg is true +if get(g:, ':netrw_suppress_gx_mesg', 1) + if &srr =~# "%s" + let s:redir = printf(&srr, has("win32") ? "nul" : "/dev/null") + else + let s:redir= &srr .. (has("win32") ? "nul" : "/dev/null") + endif +else + let s:redir= "" +endif + +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' + else + s:cmd = '' + endif + function s:Open(cmd, file) + if empty(a:cmd) && !exists('g:netrw_browsex_viewer') + echoerr "No program to open this path found. See :help Open for more information." + else + Launch cmd shellescape(a:file, 1) + endif + endfunction + command -complete=file -nargs=1 Open call s:Open(s:cmd, <q-args>) +endif + +if !exists('g:netrw_regex_url') + let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}' +endif + +" " }}} " Local Browsing Autocmds: {{{2 augroup FileExplorer au! |