blob: 0038ee7dd436184b74d00744a03b1bf52c0b19b1 [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)
Christian Brabandtd49ba7b2025-03-09 10:15:39 +01009" 2025 Mar 09 by Vim Project (set b:match_skip)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
Bram Moolenaar71b6d332022-09-10 13:13:14 +010011if exists("b:did_ftplugin")
12 finish
13endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000014let b:did_ftplugin = 1
15
Bram Moolenaar071d4272004-06-13 20:20:40 +000016let s:save_cpo = &cpo
17set cpo-=C
18
dkearnse84d2d42024-02-28 06:00:32 +110019setlocal comments=b:#
Bram Moolenaar71b6d332022-09-10 13:13:14 +010020setlocal commentstring=#\ %s
21setlocal formatoptions-=t formatoptions+=croql
22
23let b:undo_ftplugin = "setl com< cms< fo<"
Bram Moolenaar071d4272004-06-13 20:20:40 +000024
25" Shell: thanks to Johannes Zellner
Bram Moolenaar71b6d332022-09-10 13:13:14 +010026if exists("loaded_matchit") && !exists("b:match_words")
27 let b:match_ignorecase = 0
28 let s:sol = '\%(;\s*\|^\s*\)\@<=' " start of line
29 let b:match_words =
30 \ s:sol .. 'if\>:' .. s:sol.'elif\>:' .. s:sol.'else\>:' .. s:sol .. 'fi\>,' ..
31 \ s:sol .. '\%(for\|while\)\>:' .. s:sol .. 'done\>,' ..
32 \ s:sol .. 'case\>:' .. s:sol .. 'esac\>'
33 unlet s:sol
Christian Brabandtd49ba7b2025-03-09 10:15:39 +010034 let b:match_skip = "synIDattr(synID(line('.'),col('.'),0),'name') =~ 'shSnglCase'"
35 let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:match_skip"
Bram Moolenaar071d4272004-06-13 20:20:40 +000036endif
37
Bram Moolenaar71b6d332022-09-10 13:13:14 +010038if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Doug Kearns93197fd2024-01-14 20:59:02 +010039 let b:browsefilter = "Bourne Shell Scripts (*.sh)\t*.sh\n" ..
40 \ "Korn Shell Scripts (*.ksh)\t*.ksh\n" ..
41 \ "Bash Shell Scripts (*.bash)\t*.bash\n"
42 if has("win32")
43 let b:browsefilter ..= "All Files (*.*)\t*\n"
44 else
45 let b:browsefilter ..= "All Files (*)\t*\n"
46 endif
Bram Moolenaar71b6d332022-09-10 13:13:14 +010047 let b:undo_ftplugin ..= " | unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000048endif
49
Luca Saccaroladf67fc02024-12-29 15:36:42 +010050let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0))
51let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0))
52let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornshell", 0))
53
54if s:is_bash
Konfektf86568f2024-09-19 19:34:40 +020055 if exists(':terminal') == 2
dkearns2a281cc2023-10-07 04:59:42 +110056 command! -buffer -nargs=1 ShKeywordPrg silent exe ':term bash -c "help "<args>" 2>/dev/null || man "<args>""'
Enno2f25e402023-08-23 21:27:50 +020057 else
D. Ben Knoble8d8cb452024-05-06 19:52:53 +020058 command! -buffer -nargs=1 ShKeywordPrg echo system('bash -c "help <args>" 2>/dev/null || MANPAGER= man "<args>"')
Enno2f25e402023-08-23 21:27:50 +020059 endif
dkearns2a281cc2023-10-07 04:59:42 +110060 setlocal keywordprg=:ShKeywordPrg
61 let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer ShKeywordPrg"
Luca Saccaroladf67fc02024-12-29 15:36:42 +010062endif
Konfekt41c7bba2024-09-19 18:19:43 +020063
Luca Saccaroladf67fc02024-12-29 15:36:42 +010064if (s:is_sh || s:is_bash || s:is_kornshell) && executable('shellcheck')
Konfekt41c7bba2024-09-19 18:19:43 +020065 if !exists('current_compiler')
66 compiler shellcheck
Luca Saccaroladf67fc02024-12-29 15:36:42 +010067 let b:undo_ftplugin ..= ' | compiler make'
Konfekt41c7bba2024-09-19 18:19:43 +020068 endif
Luca Saccaroladf67fc02024-12-29 15:36:42 +010069elseif s:is_bash
70 if !exists('current_compiler')
71 compiler bash
72 let b:undo_ftplugin ..= ' | compiler make'
73 endif
Enno2f25e402023-08-23 21:27:50 +020074endif
75
Bram Moolenaar071d4272004-06-13 20:20:40 +000076let &cpo = s:save_cpo
Luca Saccaroladf67fc02024-12-29 15:36:42 +010077unlet s:save_cpo s:is_sh s:is_bash s:is_kornshell
Bram Moolenaar71b6d332022-09-10 13:13:14 +010078
79" vim: nowrap sw=2 sts=2 ts=8 noet: