blob: 54ae73b67558dc0d6a882af959ff7797c98d993f [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
Bram Moolenaar71b6d332022-09-10 13:13:14 +01002" Language: sh
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
4" Previous Maintainer: Dan Sharp
dkearns2ac708b2023-08-30 06:24:37 +10005" Contributor: Enno Nagel <ennonagel+vim@gmail.com>
dkearns2a281cc2023-10-07 04:59:42 +11006" Eisuke Kawashima
Konfekt41c7bba2024-09-19 18:19:43 +02007" Last Change: 2024 Sep 19 by Vim Project (compiler shellcheck)
Luca Saccaroladf67fc02024-12-29 15:36:42 +01008" 2024 Dec 29 by Vim Project (improve setting shellcheck compiler)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
Bram Moolenaar71b6d332022-09-10 13:13:14 +010010if exists("b:did_ftplugin")
11 finish
12endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000013let b:did_ftplugin = 1
14
Bram Moolenaar071d4272004-06-13 20:20:40 +000015let s:save_cpo = &cpo
16set cpo-=C
17
dkearnse84d2d42024-02-28 06:00:32 +110018setlocal comments=b:#
Bram Moolenaar71b6d332022-09-10 13:13:14 +010019setlocal commentstring=#\ %s
20setlocal formatoptions-=t formatoptions+=croql
21
22let b:undo_ftplugin = "setl com< cms< fo<"
Bram Moolenaar071d4272004-06-13 20:20:40 +000023
24" Shell: thanks to Johannes Zellner
Bram Moolenaar71b6d332022-09-10 13:13:14 +010025if exists("loaded_matchit") && !exists("b:match_words")
26 let b:match_ignorecase = 0
27 let s:sol = '\%(;\s*\|^\s*\)\@<=' " start of line
28 let b:match_words =
29 \ s:sol .. 'if\>:' .. s:sol.'elif\>:' .. s:sol.'else\>:' .. s:sol .. 'fi\>,' ..
30 \ s:sol .. '\%(for\|while\)\>:' .. s:sol .. 'done\>,' ..
31 \ s:sol .. 'case\>:' .. s:sol .. 'esac\>'
32 unlet s:sol
33 let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words"
Bram Moolenaar071d4272004-06-13 20:20:40 +000034endif
35
Bram Moolenaar71b6d332022-09-10 13:13:14 +010036if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Doug Kearns93197fd2024-01-14 20:59:02 +010037 let b:browsefilter = "Bourne Shell Scripts (*.sh)\t*.sh\n" ..
38 \ "Korn Shell Scripts (*.ksh)\t*.ksh\n" ..
39 \ "Bash Shell Scripts (*.bash)\t*.bash\n"
40 if has("win32")
41 let b:browsefilter ..= "All Files (*.*)\t*\n"
42 else
43 let b:browsefilter ..= "All Files (*)\t*\n"
44 endif
Bram Moolenaar71b6d332022-09-10 13:13:14 +010045 let b:undo_ftplugin ..= " | unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000046endif
47
Luca Saccaroladf67fc02024-12-29 15:36:42 +010048let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0))
49let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0))
50let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornshell", 0))
51
52if s:is_bash
Konfektf86568f2024-09-19 19:34:40 +020053 if exists(':terminal') == 2
dkearns2a281cc2023-10-07 04:59:42 +110054 command! -buffer -nargs=1 ShKeywordPrg silent exe ':term bash -c "help "<args>" 2>/dev/null || man "<args>""'
Enno2f25e402023-08-23 21:27:50 +020055 else
D. Ben Knoble8d8cb452024-05-06 19:52:53 +020056 command! -buffer -nargs=1 ShKeywordPrg echo system('bash -c "help <args>" 2>/dev/null || MANPAGER= man "<args>"')
Enno2f25e402023-08-23 21:27:50 +020057 endif
dkearns2a281cc2023-10-07 04:59:42 +110058 setlocal keywordprg=:ShKeywordPrg
59 let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer ShKeywordPrg"
Luca Saccaroladf67fc02024-12-29 15:36:42 +010060endif
Konfekt41c7bba2024-09-19 18:19:43 +020061
Luca Saccaroladf67fc02024-12-29 15:36:42 +010062if (s:is_sh || s:is_bash || s:is_kornshell) && executable('shellcheck')
Konfekt41c7bba2024-09-19 18:19:43 +020063 if !exists('current_compiler')
64 compiler shellcheck
Luca Saccaroladf67fc02024-12-29 15:36:42 +010065 let b:undo_ftplugin ..= ' | compiler make'
Konfekt41c7bba2024-09-19 18:19:43 +020066 endif
Luca Saccaroladf67fc02024-12-29 15:36:42 +010067elseif s:is_bash
68 if !exists('current_compiler')
69 compiler bash
70 let b:undo_ftplugin ..= ' | compiler make'
71 endif
Enno2f25e402023-08-23 21:27:50 +020072endif
73
Bram Moolenaar071d4272004-06-13 20:20:40 +000074let &cpo = s:save_cpo
Luca Saccaroladf67fc02024-12-29 15:36:42 +010075unlet s:save_cpo s:is_sh s:is_bash s:is_kornshell
Bram Moolenaar71b6d332022-09-10 13:13:14 +010076
77" vim: nowrap sw=2 sts=2 ts=8 noet: