blob: 3747d99dc0d703381bb854a61ccef428d0105b47 [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 Moolenaarac7bd632013-03-19 11:35:58 +01005" Last Change: Mar 04, 2013
6" Version: 129
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00007" URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
Bram Moolenaarc236c162008-07-13 17:41:49 +00008" For options and settings, please use: :help ft-sh-syntax
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +02009" This file includes many ideas from ?ric 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" AFAICT "." should be considered part of the iskeyword. Using iskeywords in
Bram Moolenaar97d62492012-11-15 21:28:22 +010020" syntax is dicey, so the following code permits the user to
21" g:sh_isk set to a string : specify iskeyword.
22" g:sh_noisk exists : don't change iskeyword
23" g:sh_noisk does not exist : (default) append "." to iskeyword
24if exists("g:sh_isk") && type(g:sh_isk) == 1 " user specifying iskeyword
25 exe "setl isk=".g:sh_isk
26elseif !exists("g:sh_noisk") " optionally prevent appending '.' to iskeyword
27 setl isk+=.
Bram Moolenaard960d762011-09-21 19:22:10 +020028endif
29
30" trying to answer the question: which shell is /bin/sh, really?
Bram Moolenaar97d62492012-11-15 21:28:22 +010031" 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 +020032if !exists("g:is_kornshell") && !exists("g:is_bash") && !exists("g:is_posix") && !exists("g:is_sh")
33 if executable("/bin/sh")
34 if resolve("/bin/sh") =~ 'bash$'
35 let g:is_bash= 1
36 elseif resolve("/bin/sh") =~ 'ksh$'
37 let g:is_ksh = 1
38 endif
39 elseif executable("/usr/bin/sh")
40 if resolve("/usr/bin//sh") =~ 'bash$'
41 let g:is_bash= 1
42 elseif resolve("/usr/bin//sh") =~ 'ksh$'
43 let g:is_ksh = 1
44 endif
45 endif
46endif
47
Bram Moolenaard4755bb2004-09-02 19:12:26 +000048" handling /bin/sh with is_kornshell/is_sh {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000049" b:is_sh is set when "#! /bin/sh" is found;
50" However, it often is just a masquerade by bash (typically Linux)
51" or kornshell (typically workstations with Posix "sh").
Bram Moolenaard960d762011-09-21 19:22:10 +020052" So, when the user sets "g:is_bash", "g:is_kornshell",
53" or "g:is_posix", a b:is_sh is converted into b:is_bash/b:is_kornshell,
Bram Moolenaar071d4272004-06-13 20:20:40 +000054" respectively.
55if !exists("b:is_kornshell") && !exists("b:is_bash")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000056 if exists("g:is_posix") && !exists("g:is_kornshell")
57 let g:is_kornshell= g:is_posix
58 endif
59 if exists("g:is_kornshell")
Bram Moolenaar071d4272004-06-13 20:20:40 +000060 let b:is_kornshell= 1
61 if exists("b:is_sh")
62 unlet b:is_sh
63 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000064 elseif exists("g:is_bash")
Bram Moolenaar071d4272004-06-13 20:20:40 +000065 let b:is_bash= 1
66 if exists("b:is_sh")
67 unlet b:is_sh
68 endif
69 else
70 let b:is_sh= 1
71 endif
72endif
73
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000074" set up default g:sh_fold_enabled {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000075if !exists("g:sh_fold_enabled")
76 let g:sh_fold_enabled= 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000077elseif g:sh_fold_enabled != 0 && !has("folding")
78 let g:sh_fold_enabled= 0
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000079 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support"
80endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000081if !exists("s:sh_fold_functions")
Bram Moolenaar97d62492012-11-15 21:28:22 +010082 let s:sh_fold_functions= and(g:sh_fold_enabled,1)
Bram Moolenaarc236c162008-07-13 17:41:49 +000083endif
84if !exists("s:sh_fold_heredoc")
Bram Moolenaar97d62492012-11-15 21:28:22 +010085 let s:sh_fold_heredoc = and(g:sh_fold_enabled,2)
Bram Moolenaarc236c162008-07-13 17:41:49 +000086endif
87if !exists("s:sh_fold_ifdofor")
Bram Moolenaar97d62492012-11-15 21:28:22 +010088 let s:sh_fold_ifdofor = and(g:sh_fold_enabled,4)
Bram Moolenaarc236c162008-07-13 17:41:49 +000089endif
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000090if g:sh_fold_enabled && &fdm == "manual"
Bram Moolenaar97d62492012-11-15 21:28:22 +010091 " Given that the user provided g:sh_fold_enabled
92 " AND g:sh_fold_enabled is manual (usual default)
93 " implies a desire for syntax-based folding
94 setl fdm=syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +000095endif
96
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000097" sh syntax is case sensitive {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000098syn case match
99
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000100" Clusters: contains=@... clusters {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101"==================================
Bram Moolenaar5c736222010-01-06 20:54:52 +0100102syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK
Bram Moolenaarc236c162008-07-13 17:41:49 +0000103if exists("b:is_kornshell")
104 syn cluster ErrorList add=shDTestError
105endif
Bram Moolenaare90ee312010-08-05 22:08:47 +0200106syn cluster shArithParenList contains=shArithmetic,shCaseEsac,shDeref,shDerefSimple,shEcho,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement
Bram Moolenaarc236c162008-07-13 17:41:49 +0000107syn cluster shArithList contains=@shArithParenList,shParenError
Bram Moolenaar5c736222010-01-06 20:54:52 +0100108syn 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 +0200109syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100110"syn cluster shColonList contains=@shCaseList
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100111syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shEcho,shEscape,shNumber,shOption,shPosnParm,shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq,shSpecial,shCmdParenRegion
Bram Moolenaar572cb562005-08-05 21:35:02 +0000112syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
Bram Moolenaar97d62492012-11-15 21:28:22 +0100113syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shEscape,shPosnParm,shCtrlSeq,shSpecial
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000114syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPPS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError
Bram Moolenaar97d62492012-11-15 21:28:22 +0100116syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shEscape,shExpr,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote
Bram Moolenaare90ee312010-08-05 22:08:47 +0200117syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000118syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest
Bram Moolenaard960d762011-09-21 19:22:10 +0200119syn 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 +0000120if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000121 syn cluster shFunctionList add=shRepeat
Bram Moolenaar7263a772007-05-10 17:35:54 +0000122 syn cluster shFunctionList add=shDblBrace,shDblParen
123endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124syn cluster shHereBeginList contains=@shCommandSubList
125syn cluster shHereList contains=shBeginHere,shHerePayload
126syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload
Bram Moolenaare90ee312010-08-05 22:08:47 +0200127syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDeref,shDerefSimple,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100128syn cluster shIfList contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo
129syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest,@shErrorList,shSet,shOption
Bram Moolenaard960d762011-09-21 19:22:10 +0200130syn cluster shSubShList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator
131syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shExDoubleQuote,shDoubleQuote,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shTestOpr,shTest,shCtrlSeq
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000132" Echo: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133" ====
134" This one is needed INSIDE a CommandSub, so that `echo bla` be correct
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200135syn 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
136syn 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 +0100137syn match shEchoQuote contained '\%(\\\\\)*\\["`'()]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138
Bram Moolenaarc236c162008-07-13 17:41:49 +0000139" This must be after the strings, so that ... \" will be correct
Bram Moolenaare90ee312010-08-05 22:08:47 +0200140syn 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 +0000141
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000142" Alias: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143" =====
144if exists("b:is_kornshell") || exists("b:is_bash")
145 syn match shStatement "\<alias\>"
Bram Moolenaard960d762011-09-21 19:22:10 +0200146 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+\)\@=" skip="\\$" end="\>\|`"
147 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+=\)\@=" skip="\\$" end="="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148endif
149
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000150" Error Codes: {{{1
151" ============
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100152if !exists("g:sh_no_error")
153 syn match shDoError "\<done\>"
154 syn match shIfError "\<fi\>"
155 syn match shInError "\<in\>"
156 syn match shCaseError ";;"
157 syn match shEsacError "\<esac\>"
158 syn match shCurlyError "}"
159 syn match shParenError ")"
160 syn match shOK '\.\(done\|fi\|in\|esac\)'
161 if exists("b:is_kornshell")
162 syn match shDTestError "]]"
163 endif
164 syn match shTestError "]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000166
Bram Moolenaarc236c162008-07-13 17:41:49 +0000167" Options: {{{1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000168" ====================
Bram Moolenaar97d62492012-11-15 21:28:22 +0100169syn match shOption "\s\zs[-+][-_a-zA-Z0-9#]\+"
Bram Moolenaarc236c162008-07-13 17:41:49 +0000170syn match shOption "\s\zs--[^ \t$`'"|]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171
Bram Moolenaar7263a772007-05-10 17:35:54 +0000172" File Redirection Highlighted As Operators: {{{1
173"===========================================
174syn match shRedir "\d\=>\(&[-0-9]\)\="
175syn match shRedir "\d\=>>-\="
176syn match shRedir "\d\=<\(&[-0-9]\)\="
177syn match shRedir "\d<<-\="
178
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000179" Operators: {{{1
180" ==========
Bram Moolenaar7263a772007-05-10 17:35:54 +0000181syn match shOperator "<<\|>>" contained
Bram Moolenaarc236c162008-07-13 17:41:49 +0000182syn match shOperator "[!&;|]" contained
183syn match shOperator "\[[[^:]\|\]]" contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184syn match shOperator "!\==" skipwhite nextgroup=shPattern
Bram Moolenaare90ee312010-08-05 22:08:47 +0200185syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000187" Subshells: {{{1
188" ==========
Bram Moolenaard960d762011-09-21 19:22:10 +0200189syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2 nextgroup=shMoreSpecial
190syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")" contains=@shSubShList nextgroup=shMoreSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000192" Tests: {{{1
193"=======
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200194syn region shExpr matchgroup=shRange start="\[" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial
Bram Moolenaar5c736222010-01-06 20:54:52 +0100195syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000196syn match shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]"
197syn match shTestOpr contained '=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern
198syn match shTestPattern contained '\w\+'
Bram Moolenaard960d762011-09-21 19:22:10 +0200199syn match shTestDoubleQuote contained '\%(\%(\\\\\)*\\\)\@<!"[^"]*"'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000200syn match shTestSingleQuote contained '\\.'
201syn match shTestSingleQuote contained "'[^']*'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202if exists("b:is_kornshell") || exists("b:is_bash")
203 syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList
204 syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList
205endif
206
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000207" Character Class In Range: {{{1
208" =========================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
210
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000211" Loops: do, if, while, until {{{1
212" ======
Bram Moolenaar97d62492012-11-15 21:28:22 +0100213if s:sh_fold_ifdofor
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000214 syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100215 syn region shIf fold transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList
Bram Moolenaar97d62492012-11-15 21:28:22 +0100216 syn region shFor fold matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000217else
218 syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100219 syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList
Bram Moolenaar97d62492012-11-15 21:28:22 +0100220 syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
221 syn match shForPP '\<for\>\ze\_s*(('
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000222endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000223if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000224 syn cluster shCaseList add=shRepeat
225 syn cluster shFunctionList add=shRepeat
226 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
227 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
228 syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000230 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList
231 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232endif
Bram Moolenaar572cb562005-08-05 21:35:02 +0000233syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList
234syn match shComma contained ","
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000236" Case: case...esac {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237" ====
Bram Moolenaarc236c162008-07-13 17:41:49 +0000238syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar
Bram Moolenaar97d62492012-11-15 21:28:22 +0100240if s:sh_fold_ifdofor
Bram Moolenaar5c736222010-01-06 20:54:52 +0100241 syn region shCase fold contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000242 syn region shCaseEsac fold matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
243else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100244 syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000245 syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
246endif
Bram Moolenaardf177f62005-02-22 08:39:57 +0000247syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
248if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200249 syn region shCaseExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100250elseif !exists("g:sh_no_error")
Bram Moolenaardf177f62005-02-22 08:39:57 +0000251 syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
252endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200253syn region shCaseSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
254syn region shCaseDoubleQuote matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar97d62492012-11-15 21:28:22 +0100256if exists("b:is_bash")
257 syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+\]+ contained contains=shCharClass
258 syn match shCharClass '\[:\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|or\|xdigit\):\]' contained
259else
260 syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+\]+ contained
261endif
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000262" Misc: {{{1
263"======
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264syn match shWrapLineOperator "\\$"
Bram Moolenaar97d62492012-11-15 21:28:22 +0100265syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
266syn match shEscape contained '\%(\\\\\)*\\.'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000268" $() and $(()): {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269" $(..) is not supported by sh (Bourne shell). However, apparently
270" some systems (HP?) have as their /bin/sh a (link to) Korn shell
271" (ie. Posix compliant shell). /bin/ksh should work for those
272" systems too, however, so the following syntax will flag $(..) as
273" an Error under /bin/sh. By consensus of vimdev'ers!
274if exists("b:is_kornshell") || exists("b:is_bash")
275 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000276 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList
Bram Moolenaar61d35bd2012-03-28 20:51:51 +0200277 syn region shArithmetic matchgroup=shArithRegion start="\$\[" skip='\\\\\|\\.' end="\]" contains=@shArithList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278 syn match shSkipInitWS contained "^\s\+"
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100279elseif !exists("g:sh_no_error")
Bram Moolenaardf177f62005-02-22 08:39:57 +0000280 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100282syn region shCmdParenRegion matchgroup=shCmdSubRegion start="(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283
284if exists("b:is_bash")
285 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
286 syn cluster shCaseList add=bashAdminStatement,bashStatement
Bram Moolenaard960d762011-09-21 19:22:10 +0200287 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 Moolenaar97d62492012-11-15 21:28:22 +0100288 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 touch
Bram Moolenaar071d4272004-06-13 20:20:40 +0000289 syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop
Bram Moolenaar97d62492012-11-15 21:28:22 +0100290 syn keyword bashStatement command compgen
Bram Moolenaar071d4272004-06-13 20:20:40 +0000291endif
292
293if exists("b:is_kornshell")
294 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
295 syn cluster shCaseList add=kshStatement
296 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 Moolenaar97d62492012-11-15 21:28:22 +0100297 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 touch tput
298 syn keyword kshStatement command setgroups setsenv
Bram Moolenaar071d4272004-06-13 20:20:40 +0000299endif
300
301syn match shSource "^\.\s"
302syn match shSource "\s\.\s"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100303"syn region shColon start="^\s*:" end="$" end="\s#"me=e-2 contains=@shColonList
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100304"syn region shColon start="^\s*\zs:" end="$" end="\s#"me=e-2
305syn match shColon '^\s*\zs:'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000307" String And Character Constants: {{{1
308"================================
Bram Moolenaar9964e462007-05-05 17:54:07 +0000309syn match shNumber "-\=\<\d\+\>#\="
310syn match shCtrlSeq "\\\d\d\d\|\\[abcfnrtv0]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000311if exists("b:is_bash")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100312 syn match shSpecial "\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000313endif
314if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200315 syn region shExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200316 syn region shExDoubleQuote matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,shSpecial
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100317elseif !exists("g:sh_no_error")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000318 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200319 syn region shExDoubleQuote matchGroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial
Bram Moolenaardf177f62005-02-22 08:39:57 +0000320endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200321syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell
Bram Moolenaard960d762011-09-21 19:22:10 +0200322syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell
323"syn region shDoubleQuote matchgroup=shQuote start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000324syn match shStringSpecial "[^[:print:] \t]" contained
Bram Moolenaar7263a772007-05-10 17:35:54 +0000325syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]"
Bram Moolenaar97d62492012-11-15 21:28:22 +0100326syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial,shComment
327syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shComment
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328syn match shMoreSpecial "\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000329
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000330" Comments: {{{1
331"==========
Bram Moolenaar5c736222010-01-06 20:54:52 +0100332syn cluster shCommentGroup contains=shTodo,@Spell
333syn keyword shTodo contained COMBAK FIXME TODO XXX
334syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup
335syn match shComment "\s\zs#.*$" contains=@shCommentGroup
Bram Moolenaar97d62492012-11-15 21:28:22 +0100336syn match shComment contained "#.*$" contains=@shCommentGroup
Bram Moolenaar5c736222010-01-06 20:54:52 +0100337syn match shQuickComment contained "#.*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000338
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000339" Here Documents: {{{1
340" =========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000341if version < 600
342 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
343 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^\s*END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
344 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
345 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
346 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
347 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
348
Bram Moolenaar97d62492012-11-15 21:28:22 +0100349elseif s:sh_fold_heredoc
350 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z([^ \t|]*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
351 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\z1\s*$"
352 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\z1\s*$"
353 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z([^ \t|]*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
354 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
355 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
356 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shRedir end="^\z1\s*$"
357 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\z1\s*$"
358 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
359 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shRedir end="^\s*\z1\s*$"
360 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
361 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\z1\s*$"
362 syn region shHereDoc matchgroup=shRedir fold start="<<\\\z([^ \t|]*\)" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364else
Bram Moolenaar97d62492012-11-15 21:28:22 +0100365 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\=\z([^ \t|]*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
366 syn region shHereDoc matchgroup=shRedir start="<<\s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\z1\s*$"
367 syn region shHereDoc matchgroup=shRedir start="<<-\s*\z([^ \t|]*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
368 syn region shHereDoc matchgroup=shRedir start="<<-\s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
369 syn region shHereDoc matchgroup=shRedir start="<<\s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\z1\s*$"
370 syn region shHereDoc matchgroup=shRedir start="<<-\s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
371 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shRedir end="^\z1\s*$"
372 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shRedir end="^\s*\z1\s*$"
373 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
374 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shRedir end="^\z1\s*$"
375 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\z1\s*$"
376 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
377 syn region shHereDoc matchgroup=shRedir start="<<\\\z([^ \t|]*\)" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378endif
379
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000380" Here Strings: {{{1
381" =============
Bram Moolenaard960d762011-09-21 19:22:10 +0200382" available for: bash; ksh (really should be ksh93 only) but not if its a posix
383if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("g:is_posix"))
Bram Moolenaar97d62492012-11-15 21:28:22 +0100384 syn match shRedir "<<<" skipwhite nextgroup=shCmdParenRegion
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000385endif
386
387" Identifiers: {{{1
388"=============
Bram Moolenaarc236c162008-07-13 17:41:49 +0000389syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained
390syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier
Bram Moolenaar97d62492012-11-15 21:28:22 +0100391syn match shSetIdentifier "=" contained nextgroup=shCmdParenRegion,shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200393 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
Bram Moolenaar97d62492012-11-15 21:28:22 +0100394 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 +0000395elseif exists("b:is_kornshell")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200396 syn region shSetList oneline matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
397 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 +0000398else
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200399 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 +0000400endif
401
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000402" Functions: {{{1
Bram Moolenaarc236c162008-07-13 17:41:49 +0000403if !exists("g:is_posix")
404 syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo
405endif
406
407if exists("b:is_bash")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100408 if s:sh_fold_functions
409 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
Bram Moolenaarc236c162008-07-13 17:41:49 +0000410 syn region shFunctionTwo fold matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
411 else
412 syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList
413 syn region shFunctionTwo matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
414 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000415else
Bram Moolenaar97d62492012-11-15 21:28:22 +0100416 if s:sh_fold_functions
Bram Moolenaarc236c162008-07-13 17:41:49 +0000417 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
418 syn region shFunctionTwo fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
419 else
420 syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList
421 syn region shFunctionTwo matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
422 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000423endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000425" Parameter Dereferencing: {{{1
426" ========================
Bram Moolenaar97d62492012-11-15 21:28:22 +0100427syn match shDerefSimple "\$\%(\k\+\|\d\)"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000428syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100429if !exists("g:sh_no_error")
430 syn match shDerefWordError "[^}$[]" contained
431endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432syn match shDerefSimple "\$[-#*@!?]"
433syn match shDerefSimple "\$\$"
434if exists("b:is_bash") || exists("b:is_kornshell")
435 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000436 syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437endif
438
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000439" bash: ${!prefix*} and ${#parameter}: {{{1
440" ====================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441if exists("b:is_bash")
442 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp
Bram Moolenaar97d62492012-11-15 21:28:22 +0100443 syn match shDerefVar contained "{\@<=!\k\+" nextgroup=@shDerefVarList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444endif
445
446syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError
447syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp
Bram Moolenaar97d62492012-11-15 21:28:22 +0100448syn match shDerefVar contained "{\@<=\k\+" nextgroup=@shDerefVarList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000450" sh ksh bash : ${var[... ]...} array reference: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError
452
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000453" Special ${parameter OPERATOR word} handling: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454" sh ksh bash : ${parameter:-word} word is default value
455" sh ksh bash : ${parameter:=word} assign word as default value
456" sh ksh bash : ${parameter:?word} display word if parameter is null
457" sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing
458" ksh bash : ${parameter#pattern} remove small left pattern
459" ksh bash : ${parameter##pattern} remove large left pattern
460" ksh bash : ${parameter%pattern} remove small right pattern
461" ksh bash : ${parameter%%pattern} remove large right pattern
Bram Moolenaard960d762011-09-21 19:22:10 +0200462" bash : ${parameter^pattern} Case modification
463" bash : ${parameter^^pattern} Case modification
464" bash : ${parameter,pattern} Case modification
465" bash : ${parameter,,pattern} Case modification
Bram Moolenaar071d4272004-06-13 20:20:40 +0000466syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100467if !exists("g:sh_no_error")
468 syn match shDerefOpError contained ":[[:punct:]]"
469endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000470syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList
471syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList
472if exists("b:is_bash") || exists("b:is_kornshell")
473 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList
474 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000475 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000477 syn match shDerefEscape contained '\%(\\\\\)*\\.'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000478endif
Bram Moolenaard960d762011-09-21 19:22:10 +0200479if exists("b:is_bash")
480 syn match shDerefOp contained "[,^]\{1,2}" nextgroup=@shDerefPatternList
481endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200482syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ contains=shStringSpecial
483syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
Bram Moolenaarc236c162008-07-13 17:41:49 +0000484syn match shDerefString contained "\\["']" nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000485
Bram Moolenaar071d4272004-06-13 20:20:40 +0000486if exists("b:is_bash")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000487 " bash : ${parameter:offset}
488 " bash : ${parameter:offset:length}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489 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 +0000490 syn match shDerefPOL contained ":[^}]\+" contains=@shCommandSubList
491
492 " bash : ${parameter//pattern/string}
493 " bash : ${parameter//pattern}
494 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft
Bram Moolenaar97d62492012-11-15 21:28:22 +0100495 syn region shDerefPPSleft contained start='.' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList
496 syn region shDerefPPSright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}' contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497endif
498
Bram Moolenaarc236c162008-07-13 17:41:49 +0000499" Arithmetic Parenthesized Expressions: {{{1
Bram Moolenaar97d62492012-11-15 21:28:22 +0100500syn region shParen matchgroup=shArithRegion start='[^$]\zs(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000501
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000502" Useful sh Keywords: {{{1
503" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
505syn keyword shConditional contained elif else then
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100506if !exists("g:sh_no_error")
507 syn keyword shCondError elif else then
508endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000510" Useful ksh Keywords: {{{1
511" ====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000512if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200513 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 +0000514 if exists("g:is_posix")
515 syn keyword shStatement command
516 else
517 syn keyword shStatement time
518 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000520" Useful bash Keywords: {{{1
521" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 if exists("b:is_bash")
523 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
524 else
525 syn keyword shStatement login newgrp
526 endif
527endif
528
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000529" Synchronization: {{{1
530" ================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531if !exists("sh_minlines")
532 let sh_minlines = 200
533endif
534if !exists("sh_maxlines")
535 let sh_maxlines = 2 * sh_minlines
536endif
537exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
538syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
539syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
540syn sync match shDoSync grouphere shDo "\<do\>"
541syn sync match shDoSync groupthere shDo "\<done\>"
542syn sync match shForSync grouphere shFor "\<for\>"
543syn sync match shForSync groupthere shFor "\<in\>"
544syn sync match shIfSync grouphere shIf "\<if\>"
545syn sync match shIfSync groupthere shIf "\<fi\>"
546syn sync match shUntilSync grouphere shRepeat "\<until\>"
547syn sync match shWhileSync grouphere shRepeat "\<while\>"
548
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000549" Default Highlighting: {{{1
550" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551hi def link shArithRegion shShellVariables
Bram Moolenaardf177f62005-02-22 08:39:57 +0000552hi def link shBeginHere shRedir
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553hi def link shCaseBar shConditional
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554hi def link shCaseCommandSub shCommandSub
555hi def link shCaseDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000556hi def link shCaseIn shConditional
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200557hi def link shQuote shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558hi def link shCaseSingleQuote shSingleQuote
559hi def link shCaseStart shConditional
560hi def link shCmdSubRegion shShellVariables
Bram Moolenaar5c736222010-01-06 20:54:52 +0100561hi def link shColon shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562hi def link shDerefOp shOperator
Bram Moolenaardf177f62005-02-22 08:39:57 +0000563hi def link shDerefPOL shDerefOp
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000564hi def link shDerefPPS shDerefOp
Bram Moolenaardf177f62005-02-22 08:39:57 +0000565hi def link shDeref shShellVariables
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200566hi def link shDerefDelim shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567hi def link shDerefSimple shDeref
568hi def link shDerefSpecial shDeref
569hi def link shDerefString shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000570hi def link shDerefVar shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571hi def link shDoubleQuote shString
572hi def link shEcho shString
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200573hi def link shEchoDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000574hi def link shEchoQuote shString
Bram Moolenaar97d62492012-11-15 21:28:22 +0100575hi def link shForPP shLoop
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576hi def link shEmbeddedEcho shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000577hi def link shEscape shCommandSub
Bram Moolenaare90ee312010-08-05 22:08:47 +0200578hi def link shExDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000579hi def link shExSingleQuote shSingleQuote
Bram Moolenaarc236c162008-07-13 17:41:49 +0000580hi def link shFunction Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581hi def link shHereDoc shString
Bram Moolenaardf177f62005-02-22 08:39:57 +0000582hi def link shHerePayload shHereDoc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583hi def link shLoop shStatement
Bram Moolenaar5c736222010-01-06 20:54:52 +0100584hi def link shMoreSpecial shSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585hi def link shOption shCommandSub
586hi def link shPattern shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000587hi def link shParen shArithmetic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588hi def link shPosnParm shShellVariables
Bram Moolenaarc236c162008-07-13 17:41:49 +0000589hi def link shQuickComment shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590hi def link shRange shOperator
591hi def link shRedir shOperator
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200592hi def link shSetListDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000593hi def link shSetOption shOption
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594hi def link shSingleQuote shString
595hi def link shSource shOperator
596hi def link shStringSpecial shSpecial
597hi def link shSubShRegion shOperator
598hi def link shTestOpr shConditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000599hi def link shTestPattern shString
600hi def link shTestDoubleQuote shString
601hi def link shTestSingleQuote shString
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602hi def link shVariable shSetList
603hi def link shWrapLineOperator shOperator
604
605if exists("b:is_bash")
606 hi def link bashAdminStatement shStatement
607 hi def link bashSpecialVariables shShellVariables
608 hi def link bashStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000609 hi def link shFunctionParen Delimiter
610 hi def link shFunctionDelim Delimiter
Bram Moolenaar97d62492012-11-15 21:28:22 +0100611 hi def link shCharClass shSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612endif
613if exists("b:is_kornshell")
614 hi def link kshSpecialVariables shShellVariables
615 hi def link kshStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000616 hi def link shFunctionParen Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617endif
618
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100619if !exists("g:sh_no_error")
620 hi def link shCaseError Error
621 hi def link shCondError Error
622 hi def link shCurlyError Error
623 hi def link shDerefError Error
624 hi def link shDerefOpError Error
625 hi def link shDerefWordError Error
626 hi def link shDoError Error
627 hi def link shEsacError Error
628 hi def link shIfError Error
629 hi def link shInError Error
630 hi def link shParenError Error
631 hi def link shTestError Error
632 if exists("b:is_kornshell")
633 hi def link shDTestError Error
634 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635endif
636
637hi def link shArithmetic Special
638hi def link shCharClass Identifier
639hi def link shSnglCase Statement
640hi def link shCommandSub Special
641hi def link shComment Comment
642hi def link shConditional Conditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000643hi def link shCtrlSeq Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644hi def link shExprRegion Delimiter
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000645hi def link shFunctionKey Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646hi def link shFunctionName Function
647hi def link shNumber Number
648hi def link shOperator Operator
649hi def link shRepeat Repeat
650hi def link shSet Statement
651hi def link shSetList Identifier
652hi def link shShellVariables PreProc
653hi def link shSpecial Special
654hi def link shStatement Statement
655hi def link shString String
656hi def link shTodo Todo
657hi def link shAlias Identifier
658
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000659" Set Current Syntax: {{{1
660" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661if exists("b:is_bash")
662 let b:current_syntax = "bash"
663elseif exists("b:is_kornshell")
664 let b:current_syntax = "ksh"
665else
666 let b:current_syntax = "sh"
667endif
668
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000669" vim: ts=16 fdm=marker