vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

sh.vim (2857B)


      1 " Vim filetype plugin file
      2 " Language:		sh
      3 " Maintainer:		Doug Kearns <dougkearns@gmail.com>
      4 " Previous Maintainer:	Dan Sharp
      5 " Contributor:		Enno Nagel <ennonagel+vim@gmail.com>
      6 "			Eisuke Kawashima
      7 " Last Change:		2024 Sep 19 by Vim Project (compiler shellcheck)
      8 "			2024 Dec 29 by Vim Project (improve setting shellcheck compiler)
      9 "			2025 Mar 09 by Vim Project (set b:match_skip)
     10 "			2025 Jul 22 by phanium (use :hor term #17822)
     11 "			2026 Jul 10 by Vim Project (pass K argument as a list, prevent shell injection)
     12 "			2026 Sep 01 by Vim Project (use correct terminal feature test)
     13 
     14 if exists("b:did_ftplugin")
     15   finish
     16 endif
     17 let b:did_ftplugin = 1
     18 
     19 let s:save_cpo = &cpo
     20 set cpo-=C
     21 
     22 setlocal comments=b:#
     23 setlocal commentstring=#\ %s
     24 setlocal formatoptions-=t formatoptions+=croql
     25 
     26 let b:undo_ftplugin = "setl com< cms< fo<"
     27 
     28 " Shell:  thanks to Johannes Zellner
     29 if exists("loaded_matchit") && !exists("b:match_words")
     30   let b:match_ignorecase = 0
     31   let s:sol = '\%(;\s*\|^\s*\)\@<='  " start of line
     32   let b:match_words =
     33 	\  s:sol .. 'if\>:' .. s:sol.'elif\>:' .. s:sol.'else\>:' .. s:sol .. 'fi\>,' ..
     34 	\  s:sol .. '\%(for\|while\)\>:' .. s:sol .. 'done\>,' ..
     35 	\  s:sol .. 'case\>:' .. s:sol .. 'esac\>'
     36   unlet s:sol
     37   let b:match_skip = "synIDattr(synID(line('.'),col('.'),0),'name') =~ 'shSnglCase'" 
     38   let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:match_skip"
     39 endif
     40 
     41 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
     42   let  b:browsefilter = "Bourne Shell Scripts (*.sh)\t*.sh\n" ..
     43 	\		"Korn Shell Scripts (*.ksh)\t*.ksh\n" ..
     44 	\		"Bash Shell Scripts (*.bash)\t*.bash\n"
     45   if has("win32")
     46     let b:browsefilter ..= "All Files (*.*)\t*\n"
     47   else
     48     let b:browsefilter ..= "All Files (*)\t*\n"
     49   endif
     50   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
     51 endif
     52 
     53 let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0))
     54 let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0))
     55 let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornshell", 0))
     56 
     57 if s:is_bash
     58   if exists('*term_start')
     59     command! -buffer -nargs=1 ShKeywordPrg call term_start(['bash', '-c', 'help "$1" 2>/dev/null || man "$1"', '--', <q-args>])
     60   else
     61     command! -buffer -nargs=1 ShKeywordPrg echo system(['bash', '-c', 'help "$1" 2>/dev/null || MANPAGER= man "$1"', '--', <q-args>])
     62   endif
     63   setlocal keywordprg=:ShKeywordPrg
     64   let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer ShKeywordPrg"
     65 endif
     66 
     67 if (s:is_sh || s:is_bash || s:is_kornshell) && executable('shellcheck')
     68   if !exists('current_compiler')
     69     compiler shellcheck
     70     let b:undo_ftplugin ..= ' | compiler make'
     71   endif
     72 elseif s:is_bash
     73   if !exists('current_compiler')
     74     compiler bash
     75     let b:undo_ftplugin ..= ' | compiler make'
     76   endif
     77 endif
     78 
     79 let &cpo = s:save_cpo
     80 unlet s:save_cpo s:is_sh s:is_bash s:is_kornshell
     81 
     82 " vim: nowrap sw=2 sts=2 ts=8 noet: