blob: 73eebc38881b9f27818f046bbff34385be224087 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: shell (sh) Korn shell (ksh) bash (sh)
3" Maintainer: Dr. Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz>
4" Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int>
Bram Moolenaard960d762011-09-21 19:22:10 +02005" Last Change: Aug 16, 2011
6" Version: 118
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
20" syntax is dicey, so the following code permits the user to prevent/override
21" its setting.
22if exists("g:sh_isk") " override support
23 exe "setlocal isk=".g:sh_isk
24elseif !exists("g:sh_noisk") " prevent modification support
25 setlocal isk+=.
26endif
27
28" trying to answer the question: which shell is /bin/sh, really?
29if !exists("g:is_kornshell") && !exists("g:is_bash") && !exists("g:is_posix") && !exists("g:is_sh")
30 if executable("/bin/sh")
31 if resolve("/bin/sh") =~ 'bash$'
32 let g:is_bash= 1
33 elseif resolve("/bin/sh") =~ 'ksh$'
34 let g:is_ksh = 1
35 endif
36 elseif executable("/usr/bin/sh")
37 if resolve("/usr/bin//sh") =~ 'bash$'
38 let g:is_bash= 1
39 elseif resolve("/usr/bin//sh") =~ 'ksh$'
40 let g:is_ksh = 1
41 endif
42 endif
43endif
44
Bram Moolenaard4755bb2004-09-02 19:12:26 +000045" handling /bin/sh with is_kornshell/is_sh {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000046" b:is_sh is set when "#! /bin/sh" is found;
47" However, it often is just a masquerade by bash (typically Linux)
48" or kornshell (typically workstations with Posix "sh").
Bram Moolenaard960d762011-09-21 19:22:10 +020049" So, when the user sets "g:is_bash", "g:is_kornshell",
50" or "g:is_posix", a b:is_sh is converted into b:is_bash/b:is_kornshell,
Bram Moolenaar071d4272004-06-13 20:20:40 +000051" respectively.
52if !exists("b:is_kornshell") && !exists("b:is_bash")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000053 if exists("g:is_posix") && !exists("g:is_kornshell")
54 let g:is_kornshell= g:is_posix
55 endif
56 if exists("g:is_kornshell")
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 let b:is_kornshell= 1
58 if exists("b:is_sh")
59 unlet b:is_sh
60 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000061 elseif exists("g:is_bash")
Bram Moolenaar071d4272004-06-13 20:20:40 +000062 let b:is_bash= 1
63 if exists("b:is_sh")
64 unlet b:is_sh
65 endif
66 else
67 let b:is_sh= 1
68 endif
69endif
70
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000071" set up default g:sh_fold_enabled {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000072if !exists("g:sh_fold_enabled")
73 let g:sh_fold_enabled= 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000074elseif g:sh_fold_enabled != 0 && !has("folding")
75 let g:sh_fold_enabled= 0
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000076 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support"
77endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000078if !exists("s:sh_fold_functions")
79 let s:sh_fold_functions = 1
80endif
81if !exists("s:sh_fold_heredoc")
82 let s:sh_fold_heredoc = 2
83endif
84if !exists("s:sh_fold_ifdofor")
85 let s:sh_fold_ifdofor = 4
86endif
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000087if g:sh_fold_enabled && &fdm == "manual"
Bram Moolenaar00a927d2010-05-14 23:24:24 +020088 setlocal fdm=syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +000089endif
90
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000091" sh syntax is case sensitive {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000092syn case match
93
Bram Moolenaard4755bb2004-09-02 19:12:26 +000094" Clusters: contains=@... clusters {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000095"==================================
Bram Moolenaar5c736222010-01-06 20:54:52 +010096syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK
Bram Moolenaarc236c162008-07-13 17:41:49 +000097if exists("b:is_kornshell")
98 syn cluster ErrorList add=shDTestError
99endif
Bram Moolenaare90ee312010-08-05 22:08:47 +0200100syn 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 +0000101syn cluster shArithList contains=@shArithParenList,shParenError
Bram Moolenaar5c736222010-01-06 20:54:52 +0100102syn 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 +0200103syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104syn cluster shColonList contains=@shCaseList
Bram Moolenaare90ee312010-08-05 22:08:47 +0200105syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq,shSpecial
Bram Moolenaar572cb562005-08-05 21:35:02 +0000106syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200107syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shPosnParm,shCtrlSeq,shSpecial
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000108syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPPS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError
Bram Moolenaare90ee312010-08-05 22:08:47 +0200110syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote
111syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq
Bram Moolenaar383f9bc2005-01-19 22:18:32 +0000112syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest
Bram Moolenaard960d762011-09-21 19:22:10 +0200113syn 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 +0000114if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000115 syn cluster shFunctionList add=shRepeat
Bram Moolenaar7263a772007-05-10 17:35:54 +0000116 syn cluster shFunctionList add=shDblBrace,shDblParen
117endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118syn cluster shHereBeginList contains=@shCommandSubList
119syn cluster shHereList contains=shBeginHere,shHerePayload
120syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload
Bram Moolenaare90ee312010-08-05 22:08:47 +0200121syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDeref,shDerefSimple,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial
Bram Moolenaarc236c162008-07-13 17:41:49 +0000122syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest,@shErrorList,shSet
Bram Moolenaard960d762011-09-21 19:22:10 +0200123syn cluster shSubShList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator
124syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shExDoubleQuote,shDoubleQuote,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shTestOpr,shTest,shCtrlSeq
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000126" Echo: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127" ====
128" This one is needed INSIDE a CommandSub, so that `echo bla` be correct
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200129syn 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
130syn 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 +0100131syn match shEchoQuote contained '\%(\\\\\)*\\["`'()]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132
Bram Moolenaarc236c162008-07-13 17:41:49 +0000133" This must be after the strings, so that ... \" will be correct
Bram Moolenaare90ee312010-08-05 22:08:47 +0200134syn 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 +0000135
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000136" Alias: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137" =====
138if exists("b:is_kornshell") || exists("b:is_bash")
139 syn match shStatement "\<alias\>"
Bram Moolenaard960d762011-09-21 19:22:10 +0200140 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+\)\@=" skip="\\$" end="\>\|`"
141 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+=\)\@=" skip="\\$" end="="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142endif
143
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000144" Error Codes: {{{1
145" ============
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146syn match shDoError "\<done\>"
147syn match shIfError "\<fi\>"
148syn match shInError "\<in\>"
149syn match shCaseError ";;"
150syn match shEsacError "\<esac\>"
151syn match shCurlyError "}"
152syn match shParenError ")"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100153syn match shOK '\.\(done\|fi\|in\|esac\)'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154if exists("b:is_kornshell")
155 syn match shDTestError "]]"
156endif
157syn match shTestError "]"
158
Bram Moolenaarc236c162008-07-13 17:41:49 +0000159" Options: {{{1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000160" ====================
Bram Moolenaarfa01c392010-07-20 12:36:02 +0200161syn match shOption "\s\zs[-+][-_a-zA-Z0-9]\+\>"
Bram Moolenaarc236c162008-07-13 17:41:49 +0000162syn match shOption "\s\zs--[^ \t$`'"|]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163
Bram Moolenaar7263a772007-05-10 17:35:54 +0000164" File Redirection Highlighted As Operators: {{{1
165"===========================================
166syn match shRedir "\d\=>\(&[-0-9]\)\="
167syn match shRedir "\d\=>>-\="
168syn match shRedir "\d\=<\(&[-0-9]\)\="
169syn match shRedir "\d<<-\="
170
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000171" Operators: {{{1
172" ==========
Bram Moolenaar7263a772007-05-10 17:35:54 +0000173syn match shOperator "<<\|>>" contained
Bram Moolenaarc236c162008-07-13 17:41:49 +0000174syn match shOperator "[!&;|]" contained
175syn match shOperator "\[[[^:]\|\]]" contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176syn match shOperator "!\==" skipwhite nextgroup=shPattern
Bram Moolenaare90ee312010-08-05 22:08:47 +0200177syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000179" Subshells: {{{1
180" ==========
Bram Moolenaard960d762011-09-21 19:22:10 +0200181syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2 nextgroup=shMoreSpecial
182syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")" contains=@shSubShList nextgroup=shMoreSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000183
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000184" Tests: {{{1
185"=======
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200186syn region shExpr matchgroup=shRange start="\[" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial
Bram Moolenaar5c736222010-01-06 20:54:52 +0100187syn 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 +0000188syn match shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]"
189syn match shTestOpr contained '=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern
190syn match shTestPattern contained '\w\+'
Bram Moolenaard960d762011-09-21 19:22:10 +0200191syn match shTestDoubleQuote contained '\%(\%(\\\\\)*\\\)\@<!"[^"]*"'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000192syn match shTestSingleQuote contained '\\.'
193syn match shTestSingleQuote contained "'[^']*'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194if exists("b:is_kornshell") || exists("b:is_bash")
195 syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList
196 syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList
197endif
198
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000199" Character Class In Range: {{{1
200" =========================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000201syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
202
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000203" Loops: do, if, while, until {{{1
204" ======
Bram Moolenaarc236c162008-07-13 17:41:49 +0000205if (g:sh_fold_enabled % (s:sh_fold_ifdofor * 2))/s:sh_fold_ifdofor
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000206 syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
Bram Moolenaard960d762011-09-21 19:22:10 +0200207 syn region shIf fold transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo
Bram Moolenaarc236c162008-07-13 17:41:49 +0000208 syn region shFor fold matchgroup=shLoop start="\<for\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000209else
210 syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
Bram Moolenaard960d762011-09-21 19:22:10 +0200211 syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo
Bram Moolenaarc236c162008-07-13 17:41:49 +0000212 syn region shFor matchgroup=shLoop start="\<for\_s" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000213endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000214if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000215 syn cluster shCaseList add=shRepeat
216 syn cluster shFunctionList add=shRepeat
217 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
218 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
219 syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000221 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList
222 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000223endif
Bram Moolenaar572cb562005-08-05 21:35:02 +0000224syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList
225syn match shComma contained ","
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000227" Case: case...esac {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228" ====
Bram Moolenaarc236c162008-07-13 17:41:49 +0000229syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar
Bram Moolenaarc236c162008-07-13 17:41:49 +0000231if (g:sh_fold_enabled % (s:sh_fold_ifdofor * 2))/s:sh_fold_ifdofor
Bram Moolenaar5c736222010-01-06 20:54:52 +0100232 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 +0000233 syn region shCaseEsac fold matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
234else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100235 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 +0000236 syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
237endif
Bram Moolenaardf177f62005-02-22 08:39:57 +0000238syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
239if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200240 syn region shCaseExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000241else
242 syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
243endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200244syn region shCaseSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
245syn region shCaseDoubleQuote matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar5c736222010-01-06 20:54:52 +0100247syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+]+ contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000249" Misc: {{{1
250"======
Bram Moolenaar071d4272004-06-13 20:20:40 +0000251syn match shWrapLineOperator "\\$"
252syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
Bram Moolenaard960d762011-09-21 19:22:10 +0200253syn match shEscape contained '\\.' contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000255" $() and $(()): {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000256" $(..) is not supported by sh (Bourne shell). However, apparently
257" some systems (HP?) have as their /bin/sh a (link to) Korn shell
258" (ie. Posix compliant shell). /bin/ksh should work for those
259" systems too, however, so the following syntax will flag $(..) as
260" an Error under /bin/sh. By consensus of vimdev'ers!
261if exists("b:is_kornshell") || exists("b:is_bash")
262 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000263 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264 syn match shSkipInitWS contained "^\s\+"
265else
Bram Moolenaardf177f62005-02-22 08:39:57 +0000266 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267endif
268
269if exists("b:is_bash")
270 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
271 syn cluster shCaseList add=bashAdminStatement,bashStatement
Bram Moolenaard960d762011-09-21 19:22:10 +0200272 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 Moolenaar071d4272004-06-13 20:20:40 +0000273 syn keyword bashStatement chmod clear complete du egrep expr fgrep find gnufind gnugrep grep install less ls mkdir mv rm rmdir rpm sed sleep sort strip tail touch
274 syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop
275endif
276
277if exists("b:is_kornshell")
278 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
279 syn cluster shCaseList add=kshStatement
280 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
281 syn keyword kshStatement cat chmod clear cp du egrep expr fgrep find grep install killall less ls mkdir mv nice printenv rm rmdir sed sort strip stty tail touch tput
282endif
283
284syn match shSource "^\.\s"
285syn match shSource "\s\.\s"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100286"syn region shColon start="^\s*:" end="$" end="\s#"me=e-2 contains=@shColonList
287syn region shColon start="^\s*\zs:" end="$" end="\s#"me=e-2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000289" String And Character Constants: {{{1
290"================================
Bram Moolenaar9964e462007-05-05 17:54:07 +0000291syn match shNumber "-\=\<\d\+\>#\="
292syn match shCtrlSeq "\\\d\d\d\|\\[abcfnrtv0]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000293if exists("b:is_bash")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100294 syn match shSpecial "\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000295endif
296if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200297 syn region shExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200298 syn region shExDoubleQuote matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,shSpecial
Bram Moolenaardf177f62005-02-22 08:39:57 +0000299else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000300 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200301 syn region shExDoubleQuote matchGroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial
Bram Moolenaardf177f62005-02-22 08:39:57 +0000302endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200303syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell
Bram Moolenaard960d762011-09-21 19:22:10 +0200304syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell
305"syn region shDoubleQuote matchgroup=shQuote start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000306syn match shStringSpecial "[^[:print:] \t]" contained
Bram Moolenaar7263a772007-05-10 17:35:54 +0000307syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100308syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial
Bram Moolenaar7263a772007-05-10 17:35:54 +0000309syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100310syn match shMoreSpecial "\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000312" Comments: {{{1
313"==========
Bram Moolenaar5c736222010-01-06 20:54:52 +0100314syn cluster shCommentGroup contains=shTodo,@Spell
315syn keyword shTodo contained COMBAK FIXME TODO XXX
316syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup
317syn match shComment "\s\zs#.*$" contains=@shCommentGroup
318syn match shQuickComment contained "#.*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000320" Here Documents: {{{1
321" =========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322if version < 600
323 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
324 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
325 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
326 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
327 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
328 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
329
Bram Moolenaarc236c162008-07-13 17:41:49 +0000330elseif (g:sh_fold_enabled % (s:sh_fold_heredoc * 2))/s:sh_fold_heredoc
Bram Moolenaar9964e462007-05-05 17:54:07 +0000331 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000332 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
333 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
334 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
335 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
336 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
337 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
338 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
339 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
340 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$"
341 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
342 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000343 syn region shHereDoc matchgroup=shRedir fold start="<<\\\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345else
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000346 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\=\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
347 syn region shHereDoc matchgroup=shRedir start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
348 syn region shHereDoc matchgroup=shRedir start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
349 syn region shHereDoc matchgroup=shRedir start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
350 syn region shHereDoc matchgroup=shRedir start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
351 syn region shHereDoc matchgroup=shRedir start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
352 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
353 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$"
354 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
355 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
356 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
357 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000358 syn region shHereDoc matchgroup=shRedir start="<<\\\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359endif
360
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000361" Here Strings: {{{1
362" =============
Bram Moolenaard960d762011-09-21 19:22:10 +0200363" available for: bash; ksh (really should be ksh93 only) but not if its a posix
364if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("g:is_posix"))
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000365 syn match shRedir "<<<"
366endif
367
368" Identifiers: {{{1
369"=============
Bram Moolenaarc236c162008-07-13 17:41:49 +0000370syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained
371syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier
Bram Moolenaare90ee312010-08-05 22:08:47 +0200372syn match shSetIdentifier "=" contained nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200374 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
375 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 +0000376elseif exists("b:is_kornshell")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200377 syn region shSetList oneline matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
378 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 +0000379else
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200380 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 +0000381endif
382
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000383" Functions: {{{1
Bram Moolenaarc236c162008-07-13 17:41:49 +0000384if !exists("g:is_posix")
385 syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo
386endif
387
388if exists("b:is_bash")
389 if (g:sh_fold_enabled % (s:sh_fold_functions * 2))/s:sh_fold_functions
390 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
391 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
392 else
393 syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList
394 syn region shFunctionTwo matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
395 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000397 if (g:sh_fold_enabled % (s:sh_fold_functions * 2))/s:sh_fold_functions
398 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
399 syn region shFunctionTwo fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
400 else
401 syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList
402 syn region shFunctionTwo matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
403 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000405
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000406" Parameter Dereferencing: {{{1
407" ========================
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000408syn match shDerefSimple "\$\%(\h\w*\|\d\)"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray
410syn match shDerefWordError "[^}$[]" contained
411syn match shDerefSimple "\$[-#*@!?]"
412syn match shDerefSimple "\$\$"
413if exists("b:is_bash") || exists("b:is_kornshell")
414 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000415 syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416endif
417
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000418" bash: ${!prefix*} and ${#parameter}: {{{1
419" ====================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420if exists("b:is_bash")
421 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp
422 syn match shDerefVar contained "{\@<=!\w\+" nextgroup=@shDerefVarList
423endif
424
425syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError
426syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp
427syn match shDerefVar contained "{\@<=\w\+" nextgroup=@shDerefVarList
428
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000429" sh ksh bash : ${var[... ]...} array reference: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError
431
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000432" Special ${parameter OPERATOR word} handling: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433" sh ksh bash : ${parameter:-word} word is default value
434" sh ksh bash : ${parameter:=word} assign word as default value
435" sh ksh bash : ${parameter:?word} display word if parameter is null
436" sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing
437" ksh bash : ${parameter#pattern} remove small left pattern
438" ksh bash : ${parameter##pattern} remove large left pattern
439" ksh bash : ${parameter%pattern} remove small right pattern
440" ksh bash : ${parameter%%pattern} remove large right pattern
Bram Moolenaard960d762011-09-21 19:22:10 +0200441" bash : ${parameter^pattern} Case modification
442" bash : ${parameter^^pattern} Case modification
443" bash : ${parameter,pattern} Case modification
444" bash : ${parameter,,pattern} Case modification
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
446syn match shDerefOpError contained ":[[:punct:]]"
447syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList
448syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList
449if exists("b:is_bash") || exists("b:is_kornshell")
450 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList
451 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000452 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000453 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000454 syn match shDerefEscape contained '\%(\\\\\)*\\.'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455endif
Bram Moolenaard960d762011-09-21 19:22:10 +0200456if exists("b:is_bash")
457 syn match shDerefOp contained "[,^]\{1,2}" nextgroup=@shDerefPatternList
458endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200459syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ contains=shStringSpecial
460syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
Bram Moolenaarc236c162008-07-13 17:41:49 +0000461syn match shDerefString contained "\\["']" nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
Bram Moolenaar071d4272004-06-13 20:20:40 +0000463if exists("b:is_bash")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000464 " bash : ${parameter:offset}
465 " bash : ${parameter:offset:length}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000466 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 +0000467 syn match shDerefPOL contained ":[^}]\+" contains=@shCommandSubList
468
469 " bash : ${parameter//pattern/string}
470 " bash : ${parameter//pattern}
471 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft
Bram Moolenaara5792f52005-11-23 21:25:05 +0000472 syn region shDerefPPSleft contained start='.' skip=@\%(\\\)\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000473 syn region shDerefPPSright contained start='.' end='\ze}' contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000474endif
475
Bram Moolenaarc236c162008-07-13 17:41:49 +0000476" Arithmetic Parenthesized Expressions: {{{1
Bram Moolenaard960d762011-09-21 19:22:10 +0200477syn region shParen matchgroup=shArithRegion start='(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000478
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000479" Useful sh Keywords: {{{1
480" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
482syn keyword shConditional contained elif else then
483syn keyword shCondError elif else then
484
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000485" Useful ksh Keywords: {{{1
486" ====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000487if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200488 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 +0000489 if exists("g:is_posix")
490 syn keyword shStatement command
491 else
492 syn keyword shStatement time
493 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000495" Useful bash Keywords: {{{1
496" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497 if exists("b:is_bash")
498 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
499 else
500 syn keyword shStatement login newgrp
501 endif
502endif
503
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000504" Synchronization: {{{1
505" ================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506if !exists("sh_minlines")
507 let sh_minlines = 200
508endif
509if !exists("sh_maxlines")
510 let sh_maxlines = 2 * sh_minlines
511endif
512exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
513syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
514syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
515syn sync match shDoSync grouphere shDo "\<do\>"
516syn sync match shDoSync groupthere shDo "\<done\>"
517syn sync match shForSync grouphere shFor "\<for\>"
518syn sync match shForSync groupthere shFor "\<in\>"
519syn sync match shIfSync grouphere shIf "\<if\>"
520syn sync match shIfSync groupthere shIf "\<fi\>"
521syn sync match shUntilSync grouphere shRepeat "\<until\>"
522syn sync match shWhileSync grouphere shRepeat "\<while\>"
523
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000524" Default Highlighting: {{{1
525" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526hi def link shArithRegion shShellVariables
Bram Moolenaardf177f62005-02-22 08:39:57 +0000527hi def link shBeginHere shRedir
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528hi def link shCaseBar shConditional
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529hi def link shCaseCommandSub shCommandSub
530hi def link shCaseDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000531hi def link shCaseIn shConditional
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200532hi def link shQuote shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533hi def link shCaseSingleQuote shSingleQuote
534hi def link shCaseStart shConditional
535hi def link shCmdSubRegion shShellVariables
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536hi def link shColon shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537hi def link shDerefOp shOperator
Bram Moolenaardf177f62005-02-22 08:39:57 +0000538hi def link shDerefPOL shDerefOp
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000539hi def link shDerefPPS shDerefOp
Bram Moolenaardf177f62005-02-22 08:39:57 +0000540hi def link shDeref shShellVariables
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200541hi def link shDerefDelim shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542hi def link shDerefSimple shDeref
543hi def link shDerefSpecial shDeref
544hi def link shDerefString shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000545hi def link shDerefVar shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546hi def link shDoubleQuote shString
547hi def link shEcho shString
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200548hi def link shEchoDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000549hi def link shEchoQuote shString
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550hi def link shEmbeddedEcho shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000551hi def link shEscape shCommandSub
Bram Moolenaare90ee312010-08-05 22:08:47 +0200552hi def link shExDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000553hi def link shExSingleQuote shSingleQuote
Bram Moolenaarc236c162008-07-13 17:41:49 +0000554hi def link shFunction Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555hi def link shHereDoc shString
Bram Moolenaardf177f62005-02-22 08:39:57 +0000556hi def link shHerePayload shHereDoc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557hi def link shLoop shStatement
Bram Moolenaar5c736222010-01-06 20:54:52 +0100558hi def link shMoreSpecial shSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559hi def link shOption shCommandSub
560hi def link shPattern shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000561hi def link shParen shArithmetic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562hi def link shPosnParm shShellVariables
Bram Moolenaarc236c162008-07-13 17:41:49 +0000563hi def link shQuickComment shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564hi def link shRange shOperator
565hi def link shRedir shOperator
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200566hi def link shSetListDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000567hi def link shSetOption shOption
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568hi def link shSingleQuote shString
569hi def link shSource shOperator
570hi def link shStringSpecial shSpecial
571hi def link shSubShRegion shOperator
572hi def link shTestOpr shConditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000573hi def link shTestPattern shString
574hi def link shTestDoubleQuote shString
575hi def link shTestSingleQuote shString
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576hi def link shVariable shSetList
577hi def link shWrapLineOperator shOperator
578
579if exists("b:is_bash")
580 hi def link bashAdminStatement shStatement
581 hi def link bashSpecialVariables shShellVariables
582 hi def link bashStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000583 hi def link shFunctionParen Delimiter
584 hi def link shFunctionDelim Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585endif
586if exists("b:is_kornshell")
587 hi def link kshSpecialVariables shShellVariables
588 hi def link kshStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000589 hi def link shFunctionParen Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590endif
591
592hi def link shCaseError Error
593hi def link shCondError Error
594hi def link shCurlyError Error
595hi def link shDerefError Error
596hi def link shDerefOpError Error
597hi def link shDerefWordError Error
598hi def link shDoError Error
599hi def link shEsacError Error
600hi def link shIfError Error
601hi def link shInError Error
602hi def link shParenError Error
603hi def link shTestError Error
604if exists("b:is_kornshell")
605 hi def link shDTestError Error
606endif
607
608hi def link shArithmetic Special
609hi def link shCharClass Identifier
610hi def link shSnglCase Statement
611hi def link shCommandSub Special
612hi def link shComment Comment
613hi def link shConditional Conditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000614hi def link shCtrlSeq Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000615hi def link shExprRegion Delimiter
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000616hi def link shFunctionKey Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617hi def link shFunctionName Function
618hi def link shNumber Number
619hi def link shOperator Operator
620hi def link shRepeat Repeat
621hi def link shSet Statement
622hi def link shSetList Identifier
623hi def link shShellVariables PreProc
624hi def link shSpecial Special
625hi def link shStatement Statement
626hi def link shString String
627hi def link shTodo Todo
628hi def link shAlias Identifier
629
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000630" Set Current Syntax: {{{1
631" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632if exists("b:is_bash")
633 let b:current_syntax = "bash"
634elseif exists("b:is_kornshell")
635 let b:current_syntax = "ksh"
636else
637 let b:current_syntax = "sh"
638endif
639
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000640" vim: ts=16 fdm=marker