blob: 3fc236f033e1a1598a12d3da0cf5fd0aec642b2d [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: shell (sh) Korn shell (ksh) bash (sh)
Bram Moolenaar97d62492012-11-15 21:28:22 +01003" Maintainer: Charles E. Campbell <NdrOchipS@PcampbellAfamily.Mbiz>
Bram Moolenaar071d4272004-06-13 20:20:40 +00004" Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int>
Bram Moolenaarf3913272016-02-25 00:00:01 +01005" Last Change: Feb 18, 2016
6" Version: 145
Bram Moolenaare2719092015-01-10 15:09:25 +01007" URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH
8" For options and settings, please use: :help ft-sh-syntax
Bram Moolenaarb4ff5182015-11-10 21:15:48 +01009" This file includes many ideas from Eric Brunet (eric.brunet@ens.fr)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
Bram Moolenaard4755bb2004-09-02 19:12:26 +000011" For version 5.x: Clear all syntax items {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000012" For version 6.x: Quit when a syntax file was already loaded
13if version < 600
14 syntax clear
15elseif exists("b:current_syntax")
16 finish
17endif
18
Bram Moolenaard960d762011-09-21 19:22:10 +020019" trying to answer the question: which shell is /bin/sh, really?
Bram Moolenaar97d62492012-11-15 21:28:22 +010020" If the user has not specified any of g:is_kornshell, g:is_bash, g:is_posix, g:is_sh, then guess.
Bram Moolenaard960d762011-09-21 19:22:10 +020021if !exists("g:is_kornshell") && !exists("g:is_bash") && !exists("g:is_posix") && !exists("g:is_sh")
Bram Moolenaarbc488a72013-07-05 21:01:22 +020022 let s:shell = ""
Bram Moolenaard960d762011-09-21 19:22:10 +020023 if executable("/bin/sh")
Bram Moolenaarbc488a72013-07-05 21:01:22 +020024 let s:shell = resolve("/bin/sh")
Bram Moolenaard960d762011-09-21 19:22:10 +020025 elseif executable("/usr/bin/sh")
Bram Moolenaarbc488a72013-07-05 21:01:22 +020026 let s:shell = resolve("/usr/bin/sh")
Bram Moolenaard960d762011-09-21 19:22:10 +020027 endif
Bram Moolenaarbc488a72013-07-05 21:01:22 +020028 if s:shell =~ 'bash$'
29 let g:is_bash= 1
30 elseif s:shell =~ 'ksh$'
31 let g:is_kornshell = 1
32 elseif s:shell =~ 'dash$'
33 let g:is_posix = 1
34 endif
35 unlet s:shell
Bram Moolenaard960d762011-09-21 19:22:10 +020036endif
37
Bram Moolenaard4755bb2004-09-02 19:12:26 +000038" handling /bin/sh with is_kornshell/is_sh {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000039" b:is_sh is set when "#! /bin/sh" is found;
40" However, it often is just a masquerade by bash (typically Linux)
41" or kornshell (typically workstations with Posix "sh").
Bram Moolenaard960d762011-09-21 19:22:10 +020042" So, when the user sets "g:is_bash", "g:is_kornshell",
43" or "g:is_posix", a b:is_sh is converted into b:is_bash/b:is_kornshell,
Bram Moolenaar071d4272004-06-13 20:20:40 +000044" respectively.
45if !exists("b:is_kornshell") && !exists("b:is_bash")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000046 if exists("g:is_posix") && !exists("g:is_kornshell")
47 let g:is_kornshell= g:is_posix
48 endif
49 if exists("g:is_kornshell")
Bram Moolenaar071d4272004-06-13 20:20:40 +000050 let b:is_kornshell= 1
51 if exists("b:is_sh")
52 unlet b:is_sh
53 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000054 elseif exists("g:is_bash")
Bram Moolenaar071d4272004-06-13 20:20:40 +000055 let b:is_bash= 1
56 if exists("b:is_sh")
57 unlet b:is_sh
58 endif
59 else
60 let b:is_sh= 1
61 endif
62endif
63
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000064" set up default g:sh_fold_enabled {{{1
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010065" ================================
Bram Moolenaar071d4272004-06-13 20:20:40 +000066if !exists("g:sh_fold_enabled")
67 let g:sh_fold_enabled= 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000068elseif g:sh_fold_enabled != 0 && !has("folding")
69 let g:sh_fold_enabled= 0
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000070 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support"
71endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000072if !exists("s:sh_fold_functions")
Bram Moolenaar97d62492012-11-15 21:28:22 +010073 let s:sh_fold_functions= and(g:sh_fold_enabled,1)
Bram Moolenaarc236c162008-07-13 17:41:49 +000074endif
75if !exists("s:sh_fold_heredoc")
Bram Moolenaar97d62492012-11-15 21:28:22 +010076 let s:sh_fold_heredoc = and(g:sh_fold_enabled,2)
Bram Moolenaarc236c162008-07-13 17:41:49 +000077endif
78if !exists("s:sh_fold_ifdofor")
Bram Moolenaar97d62492012-11-15 21:28:22 +010079 let s:sh_fold_ifdofor = and(g:sh_fold_enabled,4)
Bram Moolenaarc236c162008-07-13 17:41:49 +000080endif
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000081if g:sh_fold_enabled && &fdm == "manual"
Bram Moolenaar97d62492012-11-15 21:28:22 +010082 " Given that the user provided g:sh_fold_enabled
83 " AND g:sh_fold_enabled is manual (usual default)
84 " implies a desire for syntax-based folding
85 setl fdm=syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +000086endif
87
Bram Moolenaare0fa3742016-02-20 15:47:01 +010088" set up the syntax-highlighting iskeyword
89if has("patch-7.4.1141")
90 exe "syn iskeyword ".&iskeyword.",-"
91endif
92
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010093" Set up folding commands for shell {{{1
94" =================================
95if s:sh_fold_functions
96 com! -nargs=* ShFoldFunctions <args> fold
97else
98 com! -nargs=* ShFoldFunctions <args>
99endif
100if s:sh_fold_heredoc
101 com! -nargs=* ShFoldHereDoc <args> fold
102else
103 com! -nargs=* ShFoldHereDoc <args>
104endif
105if s:sh_fold_ifdofor
106 com! -nargs=* ShFoldIfDoFor <args> fold
107else
108 com! -nargs=* ShFoldIfDoFor <args>
109endif
110
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000111" sh syntax is case sensitive {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112syn case match
113
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000114" Clusters: contains=@... clusters {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115"==================================
Bram Moolenaar5c736222010-01-06 20:54:52 +0100116syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK
Bram Moolenaarc236c162008-07-13 17:41:49 +0000117if exists("b:is_kornshell")
118 syn cluster ErrorList add=shDTestError
119endif
Bram Moolenaar83d1b192015-04-13 14:22:40 +0200120syn cluster shArithParenList contains=shArithmetic,shCaseEsac,shComment,shDeref,shDo,shDerefSimple,shEcho,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement,shIf,shFor
Bram Moolenaarc236c162008-07-13 17:41:49 +0000121syn cluster shArithList contains=@shArithParenList,shParenError
Bram Moolenaar5c736222010-01-06 20:54:52 +0100122syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial,shCaseRange
Bram Moolenaard960d762011-09-21 19:22:10 +0200123syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq
Bram Moolenaare392eb42015-11-19 20:38:09 +0100124syn cluster shCommandSubList contains=shAlias,shArithmetic,shComment,shCmdParenRegion,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shOption,shPosnParm,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable
Bram Moolenaar572cb562005-08-05 21:35:02 +0000125syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
Bram Moolenaar97d62492012-11-15 21:28:22 +0100126syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shEscape,shPosnParm,shCtrlSeq,shSpecial
Bram Moolenaaracb4f222016-01-10 15:59:26 +0100127syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPSR,shDerefPPS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError
Bram Moolenaar97d62492012-11-15 21:28:22 +0100129syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shEscape,shExpr,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote
Bram Moolenaare90ee312010-08-05 22:08:47 +0200130syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000131syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest
Bram Moolenaard960d762011-09-21 19:22:10 +0200132syn cluster shFunctionList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shOption,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shCtrlSeq
Bram Moolenaar7263a772007-05-10 17:35:54 +0000133if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000134 syn cluster shFunctionList add=shRepeat
Bram Moolenaar7263a772007-05-10 17:35:54 +0000135 syn cluster shFunctionList add=shDblBrace,shDblParen
136endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137syn cluster shHereBeginList contains=@shCommandSubList
138syn cluster shHereList contains=shBeginHere,shHerePayload
139syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200140syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDeref,shDerefSimple,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial,shAtExpr
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100141syn cluster shIfList contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100142syn cluster shLoopList contains=@shCaseList,@shErrorList,shCaseEsac,shConditional,shDblBrace,shExpr,shFor,shForPP,shIf,shOption,shSet,shTest,shTestOpr,shTouch
Bram Moolenaard960d762011-09-21 19:22:10 +0200143syn cluster shSubShList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator
Bram Moolenaar60cce2f2015-10-13 23:21:27 +0200144syn cluster shTestList contains=shCharClass,shCommandSub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100145
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000146" Echo: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000147" ====
148" This one is needed INSIDE a CommandSub, so that `echo bla` be correct
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200149syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=@shEchoList skipwhite nextgroup=shQuickComment
150syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=@shEchoList skipwhite nextgroup=shQuickComment
Bram Moolenaar5c736222010-01-06 20:54:52 +0100151syn match shEchoQuote contained '\%(\\\\\)*\\["`'()]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152
Bram Moolenaarc236c162008-07-13 17:41:49 +0000153" This must be after the strings, so that ... \" will be correct
Bram Moolenaare90ee312010-08-05 22:08:47 +0200154syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shExDoubleQuote,shDoubleQuote,shCharClass,shCtrlSeq
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000156" Alias: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157" =====
158if exists("b:is_kornshell") || exists("b:is_bash")
159 syn match shStatement "\<alias\>"
Bram Moolenaard960d762011-09-21 19:22:10 +0200160 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+\)\@=" skip="\\$" end="\>\|`"
161 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+=\)\@=" skip="\\$" end="="
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100162
163 " Touch: {{{1
164 " =====
165 syn match shTouch '\<touch\>[^;#]*' skipwhite nextgroup=shTouchList contains=shTouchCmd
166 syn match shTouchCmd '\<touch\>' contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167endif
168
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000169" Error Codes: {{{1
170" ============
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100171if !exists("g:sh_no_error")
Bram Moolenaare2719092015-01-10 15:09:25 +0100172 syn match shDoError "\<done\>"
173 syn match shIfError "\<fi\>"
174 syn match shInError "\<in\>"
175 syn match shCaseError ";;"
176 syn match shEsacError "\<esac\>"
177 syn match shCurlyError "}"
178 syn match shParenError ")"
179 syn match shOK '\.\(done\|fi\|in\|esac\)'
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100180 if exists("b:is_kornshell")
Bram Moolenaare2719092015-01-10 15:09:25 +0100181 syn match shDTestError "]]"
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100182 endif
Bram Moolenaare2719092015-01-10 15:09:25 +0100183 syn match shTestError "]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185
Bram Moolenaarc236c162008-07-13 17:41:49 +0000186" Options: {{{1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000187" ====================
Bram Moolenaar97d62492012-11-15 21:28:22 +0100188syn match shOption "\s\zs[-+][-_a-zA-Z0-9#]\+"
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200189syn match shOption "\s\zs--[^ \t$`'"|);]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190
Bram Moolenaar7263a772007-05-10 17:35:54 +0000191" File Redirection Highlighted As Operators: {{{1
192"===========================================
193syn match shRedir "\d\=>\(&[-0-9]\)\="
194syn match shRedir "\d\=>>-\="
195syn match shRedir "\d\=<\(&[-0-9]\)\="
196syn match shRedir "\d<<-\="
197
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000198" Operators: {{{1
199" ==========
Bram Moolenaar7263a772007-05-10 17:35:54 +0000200syn match shOperator "<<\|>>" contained
Bram Moolenaarc236c162008-07-13 17:41:49 +0000201syn match shOperator "[!&;|]" contained
202syn match shOperator "\[[[^:]\|\]]" contained
Bram Moolenaar541f92d2015-06-19 13:27:23 +0200203syn match shOperator "[-=/*+%]\==" skipwhite nextgroup=shPattern
Bram Moolenaare90ee312010-08-05 22:08:47 +0200204syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000205
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000206" Subshells: {{{1
207" ==========
Bram Moolenaard960d762011-09-21 19:22:10 +0200208syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2 nextgroup=shMoreSpecial
209syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")" contains=@shSubShList nextgroup=shMoreSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000211" Tests: {{{1
212"=======
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200213syn region shExpr matchgroup=shRange start="\[" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial
Bram Moolenaar5c736222010-01-06 20:54:52 +0100214syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100215syn region shNoQuote start='\S' skip='\%(\\\\\)*\\.' end='\ze\s' contained
Bram Moolenaar541f92d2015-06-19 13:27:23 +0200216syn match shTestOpr contained '[^-+/%]\zs=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100217syn match shTestOpr contained "<=\|>=\|!=\|==\|=\~\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000218syn match shTestPattern contained '\w\+'
Bram Moolenaar83d1b192015-04-13 14:22:40 +0200219syn region shTestDoubleQuote contained start='\%(\%(\\\\\)*\\\)\@<!"' skip=+\\\\\|\\"+ end='"'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000220syn match shTestSingleQuote contained '\\.'
221syn match shTestSingleQuote contained "'[^']*'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100223 syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\%(\\\\\)*\\$+ end="\]\]" contains=@shTestList,shNoQuote,shComment
224 syn region shDblParen matchgroup=Delimiter start="((" skip=+\%(\\\\\)*\\$+ end="))" contains=@shTestList,shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225endif
226
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000227" Character Class In Range: {{{1
228" =========================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
230
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000231" Loops: do, if, while, until {{{1
232" ======
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100233ShFoldIfDoFor syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
234ShFoldIfDoFor syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList
235ShFoldIfDoFor syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
236ShFoldIfDoFor syn region shForPP matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=shTestOpr
237
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000239 syn cluster shCaseList add=shRepeat
240 syn cluster shFunctionList add=shRepeat
241 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
242 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
243 syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000245 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList
246 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247endif
Bram Moolenaar572cb562005-08-05 21:35:02 +0000248syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList
249syn match shComma contained ","
Bram Moolenaar071d4272004-06-13 20:20:40 +0000250
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000251" Case: case...esac {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252" ====
Bram Moolenaarc236c162008-07-13 17:41:49 +0000253syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100255ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment
256ShFoldIfDoFor syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
257
Bram Moolenaardf177f62005-02-22 08:39:57 +0000258syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
259if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200260 syn region shCaseExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100261elseif !exists("g:sh_no_error")
Bram Moolenaardf177f62005-02-22 08:39:57 +0000262 syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
263endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200264syn region shCaseSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
265syn region shCaseDoubleQuote matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar97d62492012-11-15 21:28:22 +0100267if exists("b:is_bash")
268 syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+\]+ contained contains=shCharClass
269 syn match shCharClass '\[:\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|or\|xdigit\):\]' contained
270else
271 syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+\]+ contained
272endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000273" Misc: {{{1
274"======
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275syn match shWrapLineOperator "\\$"
Bram Moolenaar97d62492012-11-15 21:28:22 +0100276syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200277syn match shEscape contained '\%(^\)\@!\%(\\\\\)*\\.'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000279" $() and $(()): {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280" $(..) is not supported by sh (Bourne shell). However, apparently
281" some systems (HP?) have as their /bin/sh a (link to) Korn shell
282" (ie. Posix compliant shell). /bin/ksh should work for those
283" systems too, however, so the following syntax will flag $(..) as
284" an Error under /bin/sh. By consensus of vimdev'ers!
285if exists("b:is_kornshell") || exists("b:is_bash")
286 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000287 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList
Bram Moolenaar61d35bd2012-03-28 20:51:51 +0200288 syn region shArithmetic matchgroup=shArithRegion start="\$\[" skip='\\\\\|\\.' end="\]" contains=@shArithList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000289 syn match shSkipInitWS contained "^\s\+"
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100290elseif !exists("g:sh_no_error")
Bram Moolenaardf177f62005-02-22 08:39:57 +0000291 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292endif
Bram Moolenaare2719092015-01-10 15:09:25 +0100293syn region shCmdParenRegion matchgroup=shCmdSubRegion start="(\ze[^(]" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000294
295if exists("b:is_bash")
296 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
297 syn cluster shCaseList add=bashAdminStatement,bashStatement
Bram Moolenaard960d762011-09-21 19:22:10 +0200298 syn keyword bashSpecialVariables contained auto_resume BASH BASH_ALIASES BASH_ALIASES BASH_ARGC BASH_ARGC BASH_ARGV BASH_ARGV BASH_CMDS BASH_CMDS BASH_COMMAND BASH_COMMAND BASH_ENV BASH_EXECUTION_STRING BASH_EXECUTION_STRING BASH_LINENO BASH_LINENO BASHOPTS BASHOPTS BASHPID BASHPID BASH_REMATCH BASH_REMATCH BASH_SOURCE BASH_SOURCE BASH_SUBSHELL BASH_SUBSHELL BASH_VERSINFO BASH_VERSION BASH_XTRACEFD BASH_XTRACEFD CDPATH COLUMNS COLUMNS COMP_CWORD COMP_CWORD COMP_KEY COMP_KEY COMP_LINE COMP_LINE COMP_POINT COMP_POINT COMPREPLY COMPREPLY COMP_TYPE COMP_TYPE COMP_WORDBREAKS COMP_WORDBREAKS COMP_WORDS COMP_WORDS COPROC COPROC DIRSTACK EMACS EMACS ENV ENV EUID FCEDIT FIGNORE FUNCNAME FUNCNAME FUNCNEST FUNCNEST GLOBIGNORE GROUPS histchars HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HISTTIMEFORMAT HISTTIMEFORMAT HOME HOSTFILE HOSTNAME HOSTTYPE IFS IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_CTYPE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_NUMERIC LINENO LINES LINES MACHTYPE MAIL MAILCHECK MAILPATH MAPFILE MAPFILE OLDPWD OPTARG OPTERR OPTIND OSTYPE PATH PIPESTATUS POSIXLY_CORRECT POSIXLY_CORRECT PPID PROMPT_COMMAND PS1 PS2 PS3 PS4 PWD RANDOM READLINE_LINE READLINE_LINE READLINE_POINT READLINE_POINT REPLY SECONDS SHELL SHELL SHELLOPTS SHLVL TIMEFORMAT TIMEOUT TMPDIR TMPDIR UID
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100299 syn keyword bashStatement chmod clear complete du egrep expr fgrep find gnufind gnugrep grep less ls mkdir mv rm rmdir rpm sed sleep sort strip tail
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300 syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop
Bram Moolenaar97d62492012-11-15 21:28:22 +0100301 syn keyword bashStatement command compgen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000302endif
303
304if exists("b:is_kornshell")
305 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
306 syn cluster shCaseList add=kshStatement
307 syn keyword kshSpecialVariables contained CDPATH COLUMNS EDITOR ENV ERRNO FCEDIT FPATH HISTFILE HISTSIZE HOME IFS LINENO LINES MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTIND PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELL TMOUT VISUAL
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100308 syn keyword kshStatement cat chmod clear cp du egrep expr fgrep find grep killall less ls mkdir mv nice printenv rm rmdir sed sort strip stty tail tput
Bram Moolenaar97d62492012-11-15 21:28:22 +0100309 syn keyword kshStatement command setgroups setsenv
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310endif
311
312syn match shSource "^\.\s"
313syn match shSource "\s\.\s"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100314"syn region shColon start="^\s*:" end="$" end="\s#"me=e-2 contains=@shColonList
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100315"syn region shColon start="^\s*\zs:" end="$" end="\s#"me=e-2
316syn match shColon '^\s*\zs:'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000318" String And Character Constants: {{{1
319"================================
Bram Moolenaar9964e462007-05-05 17:54:07 +0000320syn match shNumber "-\=\<\d\+\>#\="
321syn match shCtrlSeq "\\\d\d\d\|\\[abcfnrtv0]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000322if exists("b:is_bash")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323 syn match shSpecial "\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000324endif
325if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200326 syn region shExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200327 syn region shExDoubleQuote matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,shSpecial
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100328elseif !exists("g:sh_no_error")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000329 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200330 syn region shExDoubleQuote matchGroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial
Bram Moolenaardf177f62005-02-22 08:39:57 +0000331endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200332syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell
Bram Moolenaard960d762011-09-21 19:22:10 +0200333syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell
Bram Moolenaar541f92d2015-06-19 13:27:23 +0200334syn match shStringSpecial "[^[:print:] \t]" contained
Bram Moolenaar7263a772007-05-10 17:35:54 +0000335syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]"
Bram Moolenaar60cce2f2015-10-13 23:21:27 +0200336syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]"
337syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]"
Bram Moolenaar541f92d2015-06-19 13:27:23 +0200338syn match shMoreSpecial "\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000340" Comments: {{{1
341"==========
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342syn cluster shCommentGroup contains=shTodo,@Spell
343syn keyword shTodo contained COMBAK FIXME TODO XXX
344syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup
345syn match shComment "\s\zs#.*$" contains=@shCommentGroup
Bram Moolenaar97d62492012-11-15 21:28:22 +0100346syn match shComment contained "#.*$" contains=@shCommentGroup
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347syn match shQuickComment contained "#.*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000349" Here Documents: {{{1
350" =========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351if version < 600
Bram Moolenaar541f92d2015-06-19 13:27:23 +0200352 syn region shHereDoc matchgroup=shHereDoc01 start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shHereDoc01 end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
353 syn region shHereDoc matchgroup=shHereDoc02 start="<<-\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shHereDoc02 end="^\s*END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
354 syn region shHereDoc matchgroup=shHereDoc03 start="<<\s*\**EOF\**" matchgroup=shHereDoc03 end="^EOF$" contains=@shDblQuoteList
355 syn region shHereDoc matchgroup=shHereDoc04 start="<<-\s*\**EOF\**" matchgroup=shHereDoc04 end="^\s*EOF$" contains=@shDblQuoteList
356 syn region shHereDoc matchgroup=shHereDoc05 start="<<\s*\**\.\**" matchgroup=shHereDoc05 end="^\.$" contains=@shDblQuoteList
357 syn region shHereDoc matchgroup=shHereDoc06 start="<<-\s*\**\.\**" matchgroup=shHereDoc06 end="^\s*\.$" contains=@shDblQuoteList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359else
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100360 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc07 start="<<\s*\\\=\z([^ \t|]\+\)" matchgroup=shHereDoc07 end="^\z1\s*$" contains=@shDblQuoteList
361 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc08 start="<<\s*\"\z([^ \t|]\+\)\"" matchgroup=shHereDoc08 end="^\z1\s*$"
362 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc09 start="<<-\s*\z([^ \t|]\+\)" matchgroup=shHereDoc09 end="^\s*\z1\s*$" contains=@shDblQuoteList
363 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc10 start="<<-\s*'\z([^ \t|]\+\)'" matchgroup=shHereDoc10 end="^\s*\z1\s*$"
364 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc11 start="<<\s*'\z([^ \t|]\+\)'" matchgroup=shHereDoc11 end="^\z1\s*$"
365 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc12 start="<<-\s*\"\z([^ \t|]\+\)\"" matchgroup=shHereDoc12 end="^\s*\z1\s*$"
366 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc13 start="<<\s*\\\_$\_s*\z([^ \t|]\+\)" matchgroup=shHereDoc13 end="^\z1\s*$" contains=@shDblQuoteList
367 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc14 start="<<\s*\\\_$\_s*'\z([^ \t|]\+\)'" matchgroup=shHereDoc14 end="^\z1\s*$"
368 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc15 start="<<\s*\\\_$\_s*\"\z([^ \t|]\+\)\"" matchgroup=shHereDoc15 end="^\z1\s*$"
369 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc16 start="<<-\s*\\\_$\_s*\z([^ \t|]\+\)" matchgroup=shHereDoc16 end="^\s*\z1\s*$"
370 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc17 start="<<-\s*\\\_$\_s*\\\z([^ \t|]\+\)" matchgroup=shHereDoc17 end="^\s*\z1\s*$"
371 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc18 start="<<-\s*\\\_$\_s*'\z([^ \t|]\+\)'" matchgroup=shHereDoc18 end="^\s*\z1\s*$"
372 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc19 start="<<-\s*\\\_$\_s*\"\z([^ \t|]\+\)\"" matchgroup=shHereDoc19 end="^\s*\z1\s*$"
373 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc20 start="<<\\\z([^ \t|]\+\)" matchgroup=shHereDoc20 end="^\z1\s*$"
374 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc21 start="<<-\s*\\\z([^ \t|]\+\)" matchgroup=shHereDoc21 end="^\s*\z1\s*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375endif
376
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000377" Here Strings: {{{1
378" =============
Bram Moolenaard960d762011-09-21 19:22:10 +0200379" available for: bash; ksh (really should be ksh93 only) but not if its a posix
380if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("g:is_posix"))
Bram Moolenaar97d62492012-11-15 21:28:22 +0100381 syn match shRedir "<<<" skipwhite nextgroup=shCmdParenRegion
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000382endif
383
384" Identifiers: {{{1
385"=============
Bram Moolenaarc236c162008-07-13 17:41:49 +0000386syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained
Bram Moolenaar541f92d2015-06-19 13:27:23 +0200387syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shVarAssign
388syn match shVarAssign "=" contained nextgroup=shCmdParenRegion,shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200389syn region shAtExpr contained start="@(" end=")" contains=@shIdList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390if exists("b:is_bash")
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200391 syn region shSetList oneline matchgroup=shSet start="\<\(declare\|typeset\|local\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+#\|=" contains=@shIdList
392 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="\ze[;|)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+=" contains=@shIdList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393elseif exists("b:is_kornshell")
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200394 syn region shSetList oneline matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
395 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396else
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200397 syn region shSetList oneline matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398endif
399
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000400" Functions: {{{1
Bram Moolenaarc236c162008-07-13 17:41:49 +0000401if !exists("g:is_posix")
402 syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo
403endif
404
405if exists("b:is_bash")
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100406 ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
407 ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\<[^d][^o]\&\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
408 ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
409 ShFoldFunctions syn region shFunctionFour matchgroup=shFunction start="\<[^d][^o]\&\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*)" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410else
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100411 ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
412 ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\<[^d][^o]\&\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
413 ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
414 ShFoldFunctions syn region shFunctionFour matchgroup=shFunction start="\<[^d][^o]\&\h\w*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000415endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000417" Parameter Dereferencing: {{{1
418" ========================
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100419if !exists("g:sh_no_error")
420 syn match shDerefWordError "[^}$[]" contained
421endif
Bram Moolenaare392eb42015-11-19 20:38:09 +0100422syn match shDerefSimple "\$\%(\k\+\|\d\)"
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100423syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424syn match shDerefSimple "\$[-#*@!?]"
425syn match shDerefSimple "\$\$"
426if exists("b:is_bash") || exists("b:is_kornshell")
427 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000428 syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429endif
430
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100431" ksh: ${!var[*]} array index list syntax: {{{1
432" ========================================
433if exists("b:is_kornshell")
434 syn region shDeref matchgroup=PreProc start="\${!" end="}" contains=@shDerefVarArray
435endif
436
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000437" bash: ${!prefix*} and ${#parameter}: {{{1
438" ====================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000439if exists("b:is_bash")
440 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp
Bram Moolenaar97d62492012-11-15 21:28:22 +0100441 syn match shDerefVar contained "{\@<=!\k\+" nextgroup=@shDerefVarList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000442endif
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100443if exists("b:is_kornshell")
444 syn match shDerefVar contained "{\@<=!\k[[:alnum:]_.]*" nextgroup=@shDerefVarList
445endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446
447syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError
448syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp
Bram Moolenaar97d62492012-11-15 21:28:22 +0100449syn match shDerefVar contained "{\@<=\k\+" nextgroup=@shDerefVarList
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100450if exists("b:is_kornshell")
451 syn match shDerefVar contained "{\@<=\k[[:alnum:]_.]*" nextgroup=@shDerefVarList
452endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000454" sh ksh bash : ${var[... ]...} array reference: {{{1
Bram Moolenaare2719092015-01-10 15:09:25 +0100455syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000457" Special ${parameter OPERATOR word} handling: {{{1
Bram Moolenaare2719092015-01-10 15:09:25 +0100458" sh ksh bash : ${parameter:-word} word is default value
459" sh ksh bash : ${parameter:=word} assign word as default value
460" sh ksh bash : ${parameter:?word} display word if parameter is null
461" sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing
462" ksh bash : ${parameter#pattern} remove small left pattern
463" ksh bash : ${parameter##pattern} remove large left pattern
464" ksh bash : ${parameter%pattern} remove small right pattern
465" ksh bash : ${parameter%%pattern} remove large right pattern
466" bash : ${parameter^pattern} Case modification
467" bash : ${parameter^^pattern} Case modification
468" bash : ${parameter,pattern} Case modification
469" bash : ${parameter,,pattern} Case modification
Bram Moolenaar071d4272004-06-13 20:20:40 +0000470syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100471if !exists("g:sh_no_error")
472 syn match shDerefOpError contained ":[[:punct:]]"
473endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000474syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList
475syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList
476if exists("b:is_bash") || exists("b:is_kornshell")
477 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList
478 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000479 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000480 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000481 syn match shDerefEscape contained '\%(\\\\\)*\\.'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482endif
Bram Moolenaard960d762011-09-21 19:22:10 +0200483if exists("b:is_bash")
484 syn match shDerefOp contained "[,^]\{1,2}" nextgroup=@shDerefPatternList
485endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200486syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ contains=shStringSpecial
487syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
Bram Moolenaarc236c162008-07-13 17:41:49 +0000488syn match shDerefString contained "\\["']" nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489
Bram Moolenaar071d4272004-06-13 20:20:40 +0000490if exists("b:is_bash")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000491 " bash : ${parameter:offset}
492 " bash : ${parameter:offset:length}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000493 syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000494 syn match shDerefPOL contained ":[^}]\+" contains=@shCommandSubList
495
496 " bash : ${parameter//pattern/string}
497 " bash : ${parameter//pattern}
498 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft
Bram Moolenaar97d62492012-11-15 21:28:22 +0100499 syn region shDerefPPSleft contained start='.' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList
500 syn region shDerefPPSright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}' contains=@shCommandSubList
Bram Moolenaaracb4f222016-01-10 15:59:26 +0100501
502 " bash : ${parameter/#substring/replacement}
503 syn match shDerefPSR contained '/#' nextgroup=shDerefPSRleft
504 syn region shDerefPSRleft contained start='.' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPSRright
505 syn region shDerefPSRright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506endif
507
Bram Moolenaarc236c162008-07-13 17:41:49 +0000508" Arithmetic Parenthesized Expressions: {{{1
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200509"syn region shParen matchgroup=shArithRegion start='[^$]\zs(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList
510syn region shParen matchgroup=shArithRegion start='\$\@!(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000511
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000512" Useful sh Keywords: {{{1
513" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
515syn keyword shConditional contained elif else then
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100516if !exists("g:sh_no_error")
517 syn keyword shCondError elif else then
518endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000520" Useful ksh Keywords: {{{1
521" ====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200523 syn keyword shStatement autoload bg false fc fg functions getopts hash history integer jobs let nohup printf r stop suspend times true type unalias whence
Bram Moolenaarc236c162008-07-13 17:41:49 +0000524 if exists("g:is_posix")
525 syn keyword shStatement command
526 else
527 syn keyword shStatement time
528 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000530" Useful bash Keywords: {{{1
531" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 if exists("b:is_bash")
533 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
534 else
535 syn keyword shStatement login newgrp
536 endif
537endif
538
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000539" Synchronization: {{{1
540" ================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541if !exists("sh_minlines")
542 let sh_minlines = 200
543endif
544if !exists("sh_maxlines")
545 let sh_maxlines = 2 * sh_minlines
546endif
547exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
548syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
549syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
550syn sync match shDoSync grouphere shDo "\<do\>"
551syn sync match shDoSync groupthere shDo "\<done\>"
552syn sync match shForSync grouphere shFor "\<for\>"
553syn sync match shForSync groupthere shFor "\<in\>"
554syn sync match shIfSync grouphere shIf "\<if\>"
555syn sync match shIfSync groupthere shIf "\<fi\>"
556syn sync match shUntilSync grouphere shRepeat "\<until\>"
557syn sync match shWhileSync grouphere shRepeat "\<while\>"
558
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000559" Default Highlighting: {{{1
560" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561hi def link shArithRegion shShellVariables
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200562hi def link shAtExpr shSetList
Bram Moolenaardf177f62005-02-22 08:39:57 +0000563hi def link shBeginHere shRedir
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564hi def link shCaseBar shConditional
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565hi def link shCaseCommandSub shCommandSub
566hi def link shCaseDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000567hi def link shCaseIn shConditional
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200568hi def link shQuote shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569hi def link shCaseSingleQuote shSingleQuote
570hi def link shCaseStart shConditional
571hi def link shCmdSubRegion shShellVariables
Bram Moolenaar5c736222010-01-06 20:54:52 +0100572hi def link shColon shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573hi def link shDerefOp shOperator
Bram Moolenaardf177f62005-02-22 08:39:57 +0000574hi def link shDerefPOL shDerefOp
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000575hi def link shDerefPPS shDerefOp
Bram Moolenaaracb4f222016-01-10 15:59:26 +0100576hi def link shDerefPSR shDerefOp
Bram Moolenaardf177f62005-02-22 08:39:57 +0000577hi def link shDeref shShellVariables
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200578hi def link shDerefDelim shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579hi def link shDerefSimple shDeref
580hi def link shDerefSpecial shDeref
581hi def link shDerefString shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000582hi def link shDerefVar shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583hi def link shDoubleQuote shString
584hi def link shEcho shString
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200585hi def link shEchoDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000586hi def link shEchoQuote shString
Bram Moolenaar83d1b192015-04-13 14:22:40 +0200587hi def link shForPP shLoop
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588hi def link shEmbeddedEcho shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000589hi def link shEscape shCommandSub
Bram Moolenaare90ee312010-08-05 22:08:47 +0200590hi def link shExDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000591hi def link shExSingleQuote shSingleQuote
Bram Moolenaarc236c162008-07-13 17:41:49 +0000592hi def link shFunction Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593hi def link shHereDoc shString
Bram Moolenaardf177f62005-02-22 08:39:57 +0000594hi def link shHerePayload shHereDoc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595hi def link shLoop shStatement
Bram Moolenaar5c736222010-01-06 20:54:52 +0100596hi def link shMoreSpecial shSpecial
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100597hi def link shNoQuote shDoubleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000598hi def link shOption shCommandSub
599hi def link shPattern shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000600hi def link shParen shArithmetic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601hi def link shPosnParm shShellVariables
Bram Moolenaarc236c162008-07-13 17:41:49 +0000602hi def link shQuickComment shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603hi def link shRange shOperator
604hi def link shRedir shOperator
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200605hi def link shSetListDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000606hi def link shSetOption shOption
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607hi def link shSingleQuote shString
608hi def link shSource shOperator
609hi def link shStringSpecial shSpecial
610hi def link shSubShRegion shOperator
611hi def link shTestOpr shConditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000612hi def link shTestPattern shString
613hi def link shTestDoubleQuote shString
614hi def link shTestSingleQuote shString
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100615hi def link shTouchCmd shStatement
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616hi def link shVariable shSetList
617hi def link shWrapLineOperator shOperator
618
619if exists("b:is_bash")
620 hi def link bashAdminStatement shStatement
621 hi def link bashSpecialVariables shShellVariables
622 hi def link bashStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000623 hi def link shFunctionParen Delimiter
624 hi def link shFunctionDelim Delimiter
Bram Moolenaar97d62492012-11-15 21:28:22 +0100625 hi def link shCharClass shSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626endif
627if exists("b:is_kornshell")
628 hi def link kshSpecialVariables shShellVariables
629 hi def link kshStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000630 hi def link shFunctionParen Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631endif
632
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100633if !exists("g:sh_no_error")
634 hi def link shCaseError Error
635 hi def link shCondError Error
636 hi def link shCurlyError Error
637 hi def link shDerefError Error
638 hi def link shDerefOpError Error
639 hi def link shDerefWordError Error
640 hi def link shDoError Error
641 hi def link shEsacError Error
642 hi def link shIfError Error
643 hi def link shInError Error
644 hi def link shParenError Error
645 hi def link shTestError Error
646 if exists("b:is_kornshell")
647 hi def link shDTestError Error
648 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649endif
650
651hi def link shArithmetic Special
652hi def link shCharClass Identifier
653hi def link shSnglCase Statement
654hi def link shCommandSub Special
655hi def link shComment Comment
656hi def link shConditional Conditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000657hi def link shCtrlSeq Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658hi def link shExprRegion Delimiter
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000659hi def link shFunctionKey Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660hi def link shFunctionName Function
661hi def link shNumber Number
662hi def link shOperator Operator
663hi def link shRepeat Repeat
664hi def link shSet Statement
665hi def link shSetList Identifier
666hi def link shShellVariables PreProc
667hi def link shSpecial Special
668hi def link shStatement Statement
669hi def link shString String
670hi def link shTodo Todo
671hi def link shAlias Identifier
Bram Moolenaar541f92d2015-06-19 13:27:23 +0200672hi def link shHereDoc01 shRedir
673hi def link shHereDoc02 shRedir
674hi def link shHereDoc03 shRedir
675hi def link shHereDoc04 shRedir
676hi def link shHereDoc05 shRedir
677hi def link shHereDoc06 shRedir
678hi def link shHereDoc07 shRedir
679hi def link shHereDoc08 shRedir
680hi def link shHereDoc09 shRedir
681hi def link shHereDoc10 shRedir
682hi def link shHereDoc11 shRedir
683hi def link shHereDoc12 shRedir
684hi def link shHereDoc13 shRedir
685hi def link shHereDoc14 shRedir
686hi def link shHereDoc15 shRedir
687hi def link shHereDoc16 shRedir
688hi def link shHereDoc17 shRedir
689hi def link shHereDoc18 shRedir
690hi def link shHereDoc19 shRedir
691hi def link shHereDoc20 shRedir
692hi def link shHereDoc21 shRedir
Bram Moolenaarb4ff5182015-11-10 21:15:48 +0100693
694" Delete shell folding commands {{{1
695" =============================
696delc ShFoldFunctions
697delc ShFoldHereDoc
698delc ShFoldIfDoFor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000700" Set Current Syntax: {{{1
701" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702if exists("b:is_bash")
703 let b:current_syntax = "bash"
704elseif exists("b:is_kornshell")
705 let b:current_syntax = "ksh"
706else
707 let b:current_syntax = "sh"
708endif
709
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000710" vim: ts=16 fdm=marker