sh.vim (68135B)
1 " Vim syntax file 2 " Language: shell (sh) Korn shell (ksh) bash (sh) 3 " Maintainer: This runtime file is looking for a new maintainer. 4 " Previous Maintainers: Charles E. Campbell 5 " Lennart Schultz <Lennart.Schultz@ecmwf.int> 6 " Last Change: 2026 Sep 15 by Vim Project 7 " Version: 208 8 " Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH 9 " For options and settings, please use: :help ft-sh-syntax 10 " This file includes many ideas from Eric Brunet (eric.brunet@ens.fr) and heredoc fixes from Felipe Contreras 11 12 " quit when a syntax file was already loaded {{{1 13 if exists("b:current_syntax") 14 finish 15 endif 16 17 " Ensure this is set unless we find another shell 18 let b:is_sh = 1 19 20 " If the shell script itself specifies which shell to use, use it 21 let s:shebang = getline(1) 22 23 if s:shebang =~ '^#!.\{-2,}\<ksh\>' 24 " The binary is too ambiguous (i.e. '/bin/ksh' or some such). 25 let b:is_kornshell = 1 26 let b:generic_korn = 1 27 elseif s:shebang =~ '^#!.\{-2,}\<ksh93u\+\>' 28 " ksh93u+ (or 93u-) release (still much too common to encounter) 29 let b:is_kornshell = 1 30 let b:is_ksh93u = 1 31 elseif s:shebang =~ '^#!.\{-2,}\<ksh93v\>' 32 " ksh93v- alpha or beta 33 let b:is_kornshell = 1 34 let b:is_ksh93v = 1 35 elseif s:shebang =~ '^#!.\{-2,}\<ksh93\>' 36 " Could be any ksh93 release 37 let b:is_kornshell = 1 38 let b:is_ksh93 = 1 39 elseif s:shebang =~ '^#!.\{-2,}\<ksh2020\>' 40 let b:is_kornshell = 1 41 let b:is_ksh2020 = 1 42 elseif s:shebang =~ '^#!.\{-2,}\<ksh88\>' 43 " The actual AT&T ksh88 and its feature set is assumed. 44 let b:is_kornshell = 1 45 let b:is_ksh88 = 1 46 elseif s:shebang =~ '^#!.\{-2,}\<mksh\>' 47 " MirBSD Korn Shell 48 let b:is_kornshell = 1 49 let b:is_mksh = 1 50 elseif s:shebang =~ '^#!.\{-2,}\<bash\>' 51 let b:is_bash = 1 52 elseif s:shebang =~ '^#!.\{-2,}\<dash\>' 53 let b:is_dash = 1 54 " handling /bin/sh with is_kornshell/is_sh {{{1 55 " b:is_sh will be set when "#! /bin/sh" is found; 56 " However, it often is just a masquerade by bash (typically Linux) 57 " or kornshell (typically workstations with Posix "sh"). 58 " So, when the user sets "g:is_kornshell", "g:is_bash", 59 " "g:is_posix" or "g:is_dash", a b:is_sh is converted into 60 " b:is_kornshell/b:is_bash/b:is_posix/b:is_dash, respectively. 61 elseif !exists("b:is_kornshell") && !exists("b:is_bash") && !exists("b:is_posix") && !exists("b:is_dash") 62 if exists("g:is_kornshell") 63 let b:is_kornshell= 1 64 let b:generic_korn = 1 65 elseif exists("g:is_bash") 66 let b:is_bash= 1 67 elseif exists("g:is_dash") 68 let b:is_dash= 1 69 elseif exists("g:is_posix") 70 let b:is_posix= 1 71 elseif exists("g:is_sh") 72 let b:is_sh= 1 73 else 74 " user did not specify which shell to use, and 75 " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous. 76 " Assuming /bin/sh is executable, and if its a link, find out what it links to. 77 let s:shell = "" 78 if executable("/bin/sh") 79 let s:shell = resolve("/bin/sh") 80 elseif executable("/usr/bin/sh") 81 let s:shell = resolve("/usr/bin/sh") 82 endif 83 if s:shell =~ '\<ksh\>' 84 " The binary is too ambiguous (i.e. '/bin/ksh' or some such). 85 let b:is_kornshell = 1 86 let b:generic_korn = 1 87 elseif s:shell =~ '\<ksh93u\+\>' 88 " ksh93u+ (or 93u-) release (still much too common to encounter) 89 let b:is_kornshell = 1 90 let b:is_ksh93u = 1 91 elseif s:shell =~ '\<ksh93v\>' 92 " ksh93v- alpha or beta 93 let b:is_kornshell = 1 94 let b:is_ksh93v = 1 95 elseif s:shell =~ '\<ksh93\>' 96 " Could be any ksh93 release 97 let b:is_kornshell = 1 98 let b:is_ksh93 = 1 99 elseif s:shebang =~ '\<ksh2020\>' 100 let b:is_kornshell = 1 101 let b:is_ksh2020 = 1 102 elseif s:shell =~ '\<ksh88\>' 103 " The actual AT&T ksh88 and its feature set is assumed. 104 let b:is_kornshell = 1 105 let b:is_ksh88 = 1 106 elseif s:shell =~ '\<mksh\>' 107 " MirBSD Korn Shell 108 let b:is_kornshell = 1 109 let b:is_mksh = 1 110 elseif s:shell =~ '\<bash\>' 111 let b:is_bash = 1 112 elseif s:shell =~ '\<dash\>' 113 let b:is_dash = 1 114 else 115 let b:is_posix = 1 116 endif 117 unlet s:shell 118 endif 119 endif 120 121 unlet s:shebang 122 123 " if b:is_dash, set b:is_posix too 124 if exists("b:is_dash") 125 let b:is_posix= 1 126 endif 127 128 if exists("b:is_kornshell") || exists("b:is_bash") 129 if exists("b:is_sh") 130 unlet b:is_sh 131 endif 132 endif 133 134 " set up default g:sh_fold_enabled {{{1 135 " ================================ 136 if !exists("g:sh_fold_enabled") 137 let g:sh_fold_enabled= 0 138 elseif g:sh_fold_enabled != 0 && !has("folding") 139 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support" 140 let g:sh_fold_enabled= 0 141 endif 142 let s:sh_fold_functions= and(g:sh_fold_enabled,1) 143 let s:sh_fold_heredoc = and(g:sh_fold_enabled,2) 144 let s:sh_fold_ifdofor = and(g:sh_fold_enabled,4) 145 if g:sh_fold_enabled && &fdm == "manual" 146 " Given that the user provided g:sh_fold_enabled 147 " AND g:sh_fold_enabled is manual (usual default) 148 " implies a desire for syntax-based folding 149 setl fdm=syntax 150 endif 151 152 " set up the syntax-highlighting for iskeyword 153 if (v:version == 704 && has("patch-7.4.1142")) || v:version > 704 154 if !exists("g:sh_syntax_isk") || (exists("g:sh_syntax_isk") && g:sh_syntax_isk) 155 if exists("b:is_bash") 156 exe "syn iskeyword ".&iskeyword.",-,:" 157 elseif exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") 158 exe "syn iskeyword ".&iskeyword.",-,." 159 else 160 exe "syn iskeyword ".&iskeyword.",-" 161 endif 162 endif 163 endif 164 165 " Set up folding commands for shell {{{1 166 " ================================= 167 if exists(":ShFoldFunctions") == 2 168 delc ShFoldFunctions 169 endif 170 if exists(":ShFoldIfHereDoc") == 2 171 delc ShFoldHereDoc 172 endif 173 if exists(":ShFoldIfDoFor") == 2 174 delc ShFoldIfDoFor 175 endif 176 if s:sh_fold_functions 177 com! -nargs=* ShFoldFunctions <args> fold 178 else 179 com! -nargs=* ShFoldFunctions <args> 180 endif 181 if s:sh_fold_heredoc 182 com! -nargs=* ShFoldHereDoc <args> fold 183 else 184 com! -nargs=* ShFoldHereDoc <args> 185 endif 186 if s:sh_fold_ifdofor 187 com! -nargs=* ShFoldIfDoFor <args> fold 188 else 189 com! -nargs=* ShFoldIfDoFor <args> 190 endif 191 192 " Set up syntax error commands for shell {{{1 193 " ====================================== 194 if exists("g:sh_no_error_rules") && type(g:sh_no_error_rules) == type([]) 195 fun! s:ScanAndCondExecSynErrCmd(idx, cmd) abort 196 let parts = matchlist(a:cmd, '\(\(\S\+\)\s\+\(\S\+\)\s*\)\{2}') 197 " Do nothing for matchable names listed in "g:sh_no_error_rules". 198 if len(parts) < a:idx || index(g:sh_no_error_rules, parts[a:idx]) < 0 199 exec a:cmd 200 endif 201 endfun 202 elseif exists("g:sh_no_error") 203 fun! s:ScanAndCondExecSynErrCmd(_, __) abort 204 endfun 205 else 206 fun! s:ScanAndCondExecSynErrCmd(_, cmd) abort 207 exec a:cmd 208 endfun 209 endif 210 211 " Read shFooError from "syn match shFooError '<pattern>'" etc. 212 com! -nargs=+ ShDefSynErrRule call s:ScanAndCondExecSynErrCmd(2, <q-args>) 213 " Read shFooError from "hi def link shFooError Error". 214 com! -nargs=+ ShLinkSynErrGroup call s:ScanAndCondExecSynErrCmd(3, <q-args>) 215 216 " Generate bracket expression items {{{1 217 " ================================= 218 " Note that the following function can be invoked as many times as necessary 219 " provided that these constraints hold for the passed dictionary argument: 220 " - every time a unique group-name value is assigned to the "itemGroup" key; 221 " - only ONCE either the "extraArgs" key is not entered or it is entered and 222 " its value does not have "contained" among other optional arguments (":help 223 " :syn-arguments"). 224 fun! s:GenerateBracketExpressionItems(dict) abort 225 let itemGroup = a:dict.itemGroup 226 let bracketGroup = a:dict.bracketGroup 227 let invGroup = itemGroup . 'Inv' 228 let skipLeftBracketGroup = itemGroup . 'SkipLeftBracket' 229 let skipRightBracketGroup = itemGroup . 'SkipRightBracket' 230 let extraArgs = has_key(a:dict, 'extraArgs') ? a:dict.extraArgs : '' 231 232 " Make the leading "[!^]" stand out in a NON-matching expression. 233 exec 'syn match ' . invGroup . ' contained "\[\@<=[!^]"' 234 235 " Set up indirections for unbalanced-bracket highlighting. 236 exec 'syn region ' . skipRightBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" matchgroup=shCollSymb end="\[\.[^]]\{-}\][^]]\{-}\.\]" matchgroup=' . itemGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . invGroup 237 exec 'syn region ' . skipLeftBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" skip="[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\%(\[[:.=]\@!\)\@=" matchgroup=' . itemGroup . ' end="\[[:.=]\@!" contains=@shBracketExprList,shDoubleQuote,' . invGroup 238 239 " Look for a general matching expression. 240 exec 'syn region ' . itemGroup . ' matchgroup=' . bracketGroup . ' start="\[\S\@=" end="\]" contains=@shBracketExprList,shDoubleQuote ' . extraArgs 241 " Look for a general NON-matching expression. 242 exec 'syn region ' . itemGroup . ' matchgroup=' . bracketGroup . ' start="\[[!^]\@=" end="\]" contains=@shBracketExprList,shDoubleQuote,' . invGroup . ' ' . extraArgs 243 244 " Accommodate unbalanced brackets in bracket expressions. The supported 245 " syntax for a plain "]" can be: "[]ws]" and "[^]ws]"; or, "[ws[.xs]ys.]zs]" 246 " and "[^ws[.xs]ys.]zs]"; see §9.3.5 RE Bracket Expression (in XBD). 247 exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipRightBracketGroup . ' ' . extraArgs 248 " Strive to handle "[]...[]" etc. 249 exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\[[:.=]\@!" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipLeftBracketGroup . ' ' . extraArgs 250 251 if !exists("g:skip_sh_syntax_inits") 252 exec 'hi def link ' . skipLeftBracketGroup . ' ' . itemGroup 253 exec 'hi def link ' . skipRightBracketGroup . ' ' . itemGroup 254 exec 'hi def link ' . invGroup . ' Underlined' 255 endif 256 endfun 257 258 call s:GenerateBracketExpressionItems({'itemGroup': 'shBracketExpr', 'bracketGroup': 'shBracketExprDelim'}) 259 260 " sh syntax is case sensitive {{{1 261 syn case match 262 263 " Clusters: contains=@... clusters {{{1 264 "================================== 265 syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK 266 if exists("b:is_kornshell") || exists("b:is_bash") 267 syn cluster ErrorList add=shDTestError 268 endif 269 syn cluster shArithParenList contains=shArithmetic,shArithParen,shCaseEsac,shComment,shDeref,shDerefVarArray,shDo,shDerefSimple,shEcho,shEscape,shExpr,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shHereString,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement,shIf,shFor 270 syn cluster shArithList contains=@shArithParenList,shParenError 271 syn cluster shBracketExprList contains=shCharClassOther,shCharClass,shCollSymb,shEqClass 272 syn cluster shCaseEsacList contains=shCaseStart,shCaseLabel,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial,shCaseRange 273 syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shComment,shDblBrace,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq 274 if exists("b:is_kornshell") || exists("b:is_bash") 275 syn cluster shCaseList add=shForPP,shDblParen 276 endif 277 syn cluster shCommandSubList contains=shAlias,shArithmetic,shBracketExpr,shCmdParenRegion,shCommandSub,shComment,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shHereDoc,shNumber,shOperator,shOption,shPosnParm,shHereString,shRedir,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable 278 syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial 279 " COMBAK: removing shEscape from shDblQuoteList fails ksh04:43 -- Jun 09, 2022: I don't see the problem with ksh04, so am reinstating shEscape 280 syn cluster shDblQuoteList contains=shArithmetic,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shDeref,shDerefSimple,shEscape,shPosnParm,shCtrlSeq,shSpecial,shSpecialDQ 281 syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPSR,shDerefPPS 282 syn cluster shDerefVarList contains=shDerefOffset,shDerefOp,shDerefVarArray,shDerefOpError 283 syn cluster shEchoList contains=shArithmetic,shBracketExpr,shCommandSub,shCommandSubBQ,shDerefVarArray,shSubshare,shValsub,shDeref,shDerefSimple,shEscape,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote 284 syn cluster shExprList1 contains=shBracketExpr,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq 285 syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest,shFunctionNameAssignError 286 syn cluster shFunctionCmds contains=shFor,shCaseEsac,shIf,shRepeat,shDblBrace,shDblParen 287 if exists("b:is_ksh88") || exists("b:is_mksh") 288 " Offer "shFunctionCmds" as is. 289 elseif exists("b:is_kornshell") || exists("b:is_bash") 290 syn cluster shFunctionCmds add=shForPP 291 else 292 syn cluster shFunctionCmds remove=shDblBrace,shDblParen 293 endif 294 syn cluster shFunctionDefList contains=shDoError,shIfError,shFunctionKey,shFunctionOne,shFunctionThree,shFunctionCmdOne 295 syn cluster shFunctionList contains=shBracketExpr,@shCommandSubList,shCaseEsac,shColon,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shOption,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shCtrlSeq,@shFunctionDefList 296 if exists("b:is_kornshell") || exists("b:is_bash") 297 syn cluster shFunctionList add=shRepeat,shDblBrace,shDblParen,shForPP 298 syn cluster shDerefList add=shCommandSubList,shEchoDeref 299 endif 300 syn cluster shHereBeginList contains=@shCommandSubList 301 syn cluster shHereList contains=shBeginHere,shHerePayload 302 syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload 303 syn cluster shIdList contains=shArithmetic,shCommandSub,shCommandSubBQ,shDerefVarArray,shSubshare,shValsub,shWrapLineOperator,shSetOption,shComment,shDeref,shDerefSimple,shHereString,shNumber,shOperator,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial,shAtExpr 304 syn cluster shIfList contains=@shLoopList,shDblBrace,shDblParen,@shFunctionDefList 305 syn cluster shLoopList contains=@shCaseList,@shErrorList,shCaseEsac,shConditional,shDblBrace,shExpr,shFor,shIf,shOption,shSet,shTest,shTestOpr,shTouch 306 if exists("b:is_kornshell") || exists("b:is_bash") 307 syn cluster shLoopList add=shForPP,shDblParen 308 endif 309 syn cluster shPPSLeftList contains=shAlias,shArithmetic,shBracketExpr,shCmdParenRegion,shCommandSub,shSubshare,shValsub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shHereDoc,shNumber,shOperator,shOption,shPosnParm,shHereString,shRedir,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable 310 syn cluster shPPSRightList contains=shDeref,shDerefSimple,shEscape,shPosnParm 311 syn cluster shSubShList contains=shBracketExpr,@shCommandSubList,shCommandSubBQ,shSubshare,shValsub,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator,shFunctionNameAssignError 312 syn cluster shTestList contains=shArithmetic,shBracketExpr,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shSpecialDQ,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr 313 syn cluster shNoZSList contains=shSpecialNoZS 314 syn cluster shForList contains=shTestOpr,shNumber,shDerefSimple,shDeref,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shArithmetic 315 316 " Echo: {{{1 317 " ==== 318 " This one is needed INSIDE a CommandSub, so that `echo bla` be correct 319 if (exists("b:is_kornshell") && !exists("b:is_ksh88")) 320 syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 end="\ze[ \t\n;]}" contains=@shEchoList skipwhite nextgroup=shQuickComment 321 syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 end="\ze[ \t\n;]}" contains=@shEchoList skipwhite nextgroup=shQuickComment 322 else 323 syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment 324 syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment 325 endif 326 if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") 327 syn region shEchoDeref contained matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment 328 syn region shEchoDeref contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment 329 endif 330 syn match shEchoQuote contained '\%(\\\\\)*\\["`'()]' 331 332 " This must be after the strings, so that ... \" will be correct 333 syn 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=shBracketExpr,shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shExDoubleQuote,shDoubleQuote,shCtrlSeq 334 335 " Alias: {{{1 336 " ===== 337 if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") 338 syn match shStatement "\<alias\>" 339 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]*\)\@=" skip="\\$" end="\>\|`" 340 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]*=\)\@=" skip="\\$" end="=" 341 342 " Touch: {{{1 343 " ===== 344 syn match shTouch '\<touch\>[^;#]*' skipwhite nextgroup=shComment contains=shTouchCmd,shDoubleQuote,shSingleQuote,shDeref,shDerefSimple,shExpr 345 syn match shTouchCmd '\<touch\>' contained 346 endif 347 348 " Error Codes: {{{1 349 " ============ 350 ShDefSynErrRule syn match shDoError "\<done\>" 351 ShDefSynErrRule syn match shIfError "\<fi\>" 352 ShDefSynErrRule syn match shInError "\<in\>" 353 ShDefSynErrRule syn match shCaseError ";;" 354 ShDefSynErrRule syn match shEsacError "\<esac\>" 355 ShDefSynErrRule syn match shCurlyError "}" 356 ShDefSynErrRule syn match shParenError ")" 357 ShDefSynErrRule syn match shOK '\.\%(done\|fi\|in\|esac\)' 358 if exists("b:is_kornshell") || exists("b:is_bash") 359 ShDefSynErrRule syn match shDTestError "]]" 360 endif 361 ShDefSynErrRule syn match shTestError "]" 362 363 " Options: {{{1 364 " ==================== 365 syn match shOption "\s\zs[-+][-_a-zA-Z#@0-9]\+" 366 syn match shOption "\s\zs--[^ \t$=`'"|);]\+" 367 368 " File Redirection Highlighted As Operators: {{{1 369 "=========================================== 370 syn match shRedir "\d\=>\(&[-0-9]\)\=" 371 syn match shRedir "\d\=>>-\=" 372 syn match shRedir "\d\=<\(&[-0-9]\)\=" 373 syn match shRedir "\d<<-\=" 374 375 " Operators: {{{1 376 " ========== 377 syn match shOperator "<<\|>>" contained 378 syn match shOperator "[!&;|]" contained 379 syn match shOperator "[-=/*+%]\==" skipwhite nextgroup=shPattern 380 syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref 381 382 " Subshells: {{{1 383 " ========== 384 syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2 nextgroup=shSpecialNxt 385 syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")" contains=@shSubShList nextgroup=shSpecialNxt 386 387 " Tests: {{{1 388 "======= 389 syn region shExpr matchgroup=shRange start="\[\s\@=" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial 390 syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1 391 syn region shNoQuote start='\S' skip='\%(\\\\\)*\\.' end='\ze\s' end="\ze['"]" contained contains=shBracketExpr,shDerefSimple,shDeref,shEscape 392 syn match shAstQuote contained '\*\ze"' nextgroup=shString 393 syn match shTestOpr contained '[^-+/%]\zs=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern 394 syn match shTestOpr contained "<=\|>=\|!=\|==\|=\~\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]" 395 syn match shTestPattern contained '\w\+' 396 syn region shTestDoubleQuote contained start='\%(\%(\\\\\)*\\\)\@<!"' skip=+\\\\\|\\"+ end='"' contains=shDeref,shDerefSimple,shDerefSpecial 397 syn match shTestSingleQuote contained '\\.' nextgroup=shTestSingleQuote 398 syn match shTestSingleQuote contained "'[^']*'" 399 if exists("b:is_kornshell") || exists("b:is_bash") 400 syn region shDblBrace matchgroup=Delimiter start="\[\[\s\@=" skip=+\%(\\\\\)*\\$+ end="\]\]" contains=@shTestList,shAstQuote,shNoQuote,shComment 401 syn region shDblParen matchgroup=Delimiter start="((" skip=+\%(\\\\\)*\\$+ end="))" contains=@shTestList,shComment 402 endif 403 404 " Character Class In Range: {{{1 405 " ========================= 406 syn match shCharClassOther contained "\[:\w\{-}:\]" 407 syn match shCharClass contained "\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|xdigit\):\]" 408 syn match shCollSymb contained "\[\..\{-}\.\]" 409 syn match shEqClass contained "\[=.\{-}=\]" 410 411 " Loops: do, if, while, until {{{1 412 " ====== 413 ShFoldIfDoFor syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList 414 ShFoldIfDoFor syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList 415 ShFoldIfDoFor syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn 416 if exists("b:is_kornshell") || exists("b:is_bash") 417 ShFoldIfDoFor syn region shForPP matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=@shForList 418 endif 419 420 if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") 421 syn cluster shCaseList add=shRepeat 422 syn cluster shFunctionList add=shRepeat 423 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace 424 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace 425 if !exists("b:is_posix") 426 syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList 427 endif 428 else 429 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList 430 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList 431 endif 432 syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList 433 syn match shComma contained "," 434 435 " Case: case...esac {{{1 436 " ==== 437 syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote 438 syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar 439 syn match shCaseLabel contained skipwhite "\%(\\.\|[-a-zA-Z0-9_*.]\)\+" contains=shBracketExpr 440 if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_ksh93u") && !exists("b:is_ksh93v") && !exists("b:is_ksh2020")) 441 ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end=";&" end=";;&" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment 442 elseif exists("b:is_kornshell") 443 ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end=";&" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment 444 else 445 ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment 446 endif 447 ShFoldIfDoFor syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList 448 449 syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote 450 if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88")) 451 syn region shCaseExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained 452 else 453 ShDefSynErrRule syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained 454 endif 455 syn region shCaseSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained 456 syn region shCaseDoubleQuote matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained 457 syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained 458 call s:GenerateBracketExpressionItems({'itemGroup': 'shCaseRange', 'bracketGroup': 'shBracketExprDelim', 'extraArgs': 'skip=+\\\\+ contained'}) 459 if exists("b:is_bash") 460 syn match shCharClass "\[:\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained 461 elseif exists("b:is_kornshell") 462 syn match shCharClass "\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained 463 endif 464 " Misc: {{{1 465 "====== 466 syn match shWrapLineOperator "\\$" 467 syn region shCommandSubBQ start="`" skip="\\\\\|\\." end="`" contains=shBQComment,@shCommandSubList 468 syn match shEscape contained '\%(^\)\@!\%(\\\\\)*\\.' 469 470 " $() and $(()): {{{1 471 " $(..) is not supported by sh (Bourne shell). However, apparently 472 " some systems (HP?) have as their /bin/sh a (link to) Korn shell 473 " (ie. Posix compliant shell). /bin/ksh should work for those 474 " systems too, however, so the following syntax will flag $(..) as 475 " an Error under /bin/sh. By consensus of vimdev'ers! 476 if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") 477 syn region shCommandSub matchgroup=shCmdSubRegion start="\$((\@!" skip='\\\\\|\\.' end=")" contains=@shCommandSubList 478 if exists("b:is_kornshell") 479 if !exists("b:is_ksh88") 480 if exists("b:is_mksh") 481 syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n]" skip='\\\\\|\\.' end="\zs[ \t\n;]}" contains=@shCommandSubList 482 else 483 syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n<]" skip='\\\\\|\\.' end="\zs[ \t\n;]}" contains=@shCommandSubList 484 endif 485 endif 486 if exists("b:is_mksh") || exists("b:generic_korn") 487 syn region shValsub matchgroup=shCmdSubRegion start="\${|" skip='\\\\\|\\.' end="}" contains=@shCommandSubList 488 endif 489 elseif exists("b:is_bash") 490 syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n]" skip='\\\\\|\\.' end="\zs[;\n][ \t\n]*}" contains=@shCommandSubList 491 syn region shValsub matchgroup=shCmdSubRegion start="\${|" skip='\\\\\|\\.' end="[;\n][ \t\n]*}" contains=@shCommandSubList 492 endif 493 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList 494 syn region shArithmetic matchgroup=shArithRegion start="\$\[" skip='\\\\\|\\.' end="\]" contains=@shArithList 495 syn match shSkipInitWS contained "^\s\+" 496 syn region shArithParen matchgroup=shArithRegion contained start="(" end=")" contains=@shArithParenList 497 else 498 ShDefSynErrRule syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList 499 endif 500 syn region shCmdParenRegion matchgroup=shCmdSubRegion start="((\@!" skip='\\\\\|\\.' end=")" contains=@shCommandSubList 501 502 if exists("b:is_bash") 503 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement 504 syn cluster shCaseList add=bashAdminStatement,bashStatement 505 syn keyword bashSpecialVariables contained auto_resume BASH BASH_ALIASES BASH_ARGC BASH_ARGV BASH_CMDS BASH_COMMAND BASH_ENV BASH_EXECUTION_STRING BASH_LINENO BASHOPTS BASHPID BASH_REMATCH BASH_SOURCE BASH_SUBSHELL BASH_VERSINFO BASH_VERSION BASH_XTRACEFD CDPATH COLUMNS COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS COPROC COPROC_PID DIRSTACK EMACS ENV EUID FCEDIT FIGNORE FUNCNAME FUNCNEST GLOBIGNORE GROUPS histchars HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HISTTIMEFORMAT HOME HOSTFILE HOSTNAME HOSTTYPE IFS IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LINENO LINES MACHTYPE MAIL MAILCHECK MAILPATH MAPFILE OLDPWD OPTARG OPTERR OPTIND OSTYPE PATH PIPESTATUS POSIXLY_CORRECT PPID PROMPT_COMMAND PS0 PS1 PS2 PS3 PS4 PWD RANDOM READLINE_LINE READLINE_POINT REPLY SECONDS SHELL SHELLOPTS SHLVL TIMEFORMAT TIMEOUT TMPDIR UID 506 syn keyword bashStatement bind builtin caller compgen complete compopt declare dirs disown enable fg help history let logout mapfile popd pushd readarray shopt source suspend time 507 syn keyword bashStatement typeset nextgroup=shSetOption 508 syn keyword bashAdminStatement reload restart start status stop 509 endif 510 511 " for all kornshells 512 if exists("b:is_kornshell") 513 syn cluster shCaseList add=kshStatement 514 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement 515 syn keyword kshSpecialVariables contained CDPATH COLUMNS EDITOR ENV FCEDIT FIGNORE FPATH HISTCMD HISTEDIT HISTFILE HISTSIZE HOME IFS JOBMAX KSH_VERSION LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME LINENO LINES MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTIND PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELL SHLVL TMOUT VISUAL 516 syn keyword kshStatement autoload builtin compound disown enum fg float functions hist history integer let nameref r redirect source stop suspend time whence 517 syn keyword shStatement typeset skipwhite nextgroup=shSetOption 518 endif 519 520 " kornshell flavors 521 if exists("b:generic_korn") 522 syn keyword kshSpecialVariables contained BASHPID EPOCHREALTIME ERRNO EXECSHELL KSHEGID KSHGID KSHUID KSH_MATCH PATHSEP PGRP PIPESTATUS TMPDIR USER_ID SH_OPTIONS COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMP_KEY COMPREPLY COMP_WORDBREAKS COMP_TYPE VPATH SRANDOM SYSTYPE CSWIDTH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.pid .sh.ppid .sh.tilde .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.sig.value.q .sh.sig.value.Q .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell .sh.install_prefix 523 syn keyword kshStatement alarm bind compgen complete eloop fds mkservice pids poll sha2sum vmstate xgrep 524 elseif exists("b:is_ksh88") 525 syn keyword kshSpecialVariables contained ERRNO 526 elseif exists("b:is_ksh93") 527 syn keyword kshSpecialVariables contained COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS CSWIDTH SH_OPTIONS SRANDOM SYSTYPE VPATH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.pid .sh.ppid .sh.tilde .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.sig.value.q .sh.sig.value.Q .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell 528 syn keyword kshStatement alarm compgen complete eloop fds mkservice pids poll sha2sum vmstate xgrep 529 elseif exists("b:is_ksh93v") 530 syn keyword kshSpecialVariables contained COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS CSWIDTH SH_OPTIONS VPATH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.sig.value.q .sh.sig.value.Q .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell 531 syn keyword kshStatement alarm compgen complete fds pids poll sha2sum vmstate xgrep 532 elseif exists("b:is_ksh93u") 533 syn keyword kshSpecialVariables contained CSWIDTH SYSTYPE VPATH .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.dollar .sh.pool .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell 534 syn keyword kshStatement alarm fds pids vmstate 535 elseif exists("b:is_ksh2020") 536 syn keyword kshSpecialVariables contained COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS SH_OPTIONS .sh .sh.edchar .sh.edcol .sh.edtext .sh.edmode .sh.name .sh.subscript .sh.value .sh.version .sh.match .sh.command .sh.file .sh.fun .sh.subshell .sh.level .sh.lineno .sh.stats .sh.math .sh.dollar .sh.pool .sh.pgrp .sh.pwdfd .sh.op_astbin .sh.sig .sh.sig.addr .sh.sig.band .sh.sig.code .sh.sig.errno .sh.sig.name .sh.sig.pid .sh.sig.signo .sh.sig.status .sh.sig.uid .sh.sig.value .sh.stats .sh.stats.arg_cachehits .sh.stats.arg_expands .sh.stats.comsubs .sh.stats.forks .sh.stats.funcalls .sh.stats.globs .sh.stats.linesread .sh.stats.nv_cachehit .sh.stats.nv_opens .sh.stats.pathsearch .sh.stats.posixfuncall .sh.stats.simplecmds .sh.stats.spawns .sh.stats.subshell .sh.install_prefix 537 syn keyword kshStatement compgen complete 538 elseif exists("b:is_mksh") 539 syn keyword kshSpecialVariables contained BASHPID EPOCHREALTIME EXECSHELL KSHEGID KSHGID KSHUID KSH_MATCH PATHSEP PGRP PIPESTATUS TMPDIR USER_ID 540 syn keyword kshStatement bind 541 endif 542 543 syn match shSource "^\.\s" 544 syn match shSource "\s\.\s" 545 if exists("b:is_kornshell") || exists("b:is_posix") 546 syn match shColon '^\s*\zs:' 547 endif 548 549 " String And Character Constants: {{{1 550 "================================ 551 syn match shNumber "\<\d\+\>#\=" 552 syn match shNumber "\<-\=\.\=\d\+\>#\=" 553 syn match shCtrlSeq "\\\d\d\d\|\\[abcfnrtv0]" contained 554 if exists("b:is_bash") || exists("b:is_kornshell") 555 syn match shSpecial "[^\\]\(\\\\\)*\zs\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained 556 syn match shSpecial "^\(\\\\\)*\zs\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained 557 syn region shExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial nextgroup=shSpecialNxt 558 syn region shExDoubleQuote matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,shSpecial nextgroup=shSpecialNxt 559 else 560 ShDefSynErrRule syn region shExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial 561 ShDefSynErrRule syn region shExDoubleQuote matchgroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial 562 endif 563 syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell nextgroup=shSpecialStart,shSpecialSQ 564 syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell nextgroup=shSpecialStart 565 syn match shStringSpecial "[^[:print:] \t]" contained 566 syn match shStringSpecial "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" nextgroup=shComment 567 syn match shSpecialSQ "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" contained nextgroup=shBkslshSnglQuote,@shNoZSList 568 syn match shSpecialDQ "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" contained nextgroup=shBkslshDblQuote,@shNoZSList 569 syn match shSpecialStart "\%(\\\\\)*\\[\\"'`$()#]" contained nextgroup=shBkslshSnglQuote,shBkslshDblQuote,@shNoZSList 570 syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]" 571 syn match shSpecialNoZS contained "\%(\\\\\)*\\[\\"'`$()#]" 572 syn match shSpecialNxt contained "\\[\\"'`$()#]" 573 574 " Comments: {{{1 575 "========== 576 syn cluster shCommentGroup contains=shTodo,@Spell 577 if exists("b:is_bash") 578 syn match shTodo contained "\<\%(COMBAK\|FIXME\|TODO\|XXX\)\ze:\=\>" 579 else 580 syn keyword shTodo contained COMBAK FIXME TODO XXX 581 endif 582 syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup 583 syn match shComment "\s\zs#.*$" contains=@shCommentGroup 584 syn match shComment contained "#.*$" contains=@shCommentGroup 585 syn match shQuickComment contained "#.*$" contains=@shCommentGroup 586 syn match shBQComment contained "#.\{-}\ze`" contains=@shCommentGroup 587 588 " Here Documents: {{{1 589 " (modified by Felipe Contreras) 590 " ========================================= 591 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc01 start="<<\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc01 end="^\z1$" contains=@shDblQuoteList 592 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc02 start="<<-\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc02 end="^\t*\z1$" contains=@shDblQuoteList 593 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc03 start="<<\s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc03 end="^\z1$" 594 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc04 start="<<-\s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc04 end="^\t*\z1$" 595 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc05 start="<<\s*'\z([^']\+\)'" matchgroup=shHereDoc05 end="^\z1$" 596 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc06 start="<<-\s*'\z([^']\+\)'" matchgroup=shHereDoc06 end="^\t*\z1$" 597 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc07 start="<<\s*\"\z([^"]\+\)\"" matchgroup=shHereDoc07 end="^\z1$" 598 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc08 start="<<-\s*\"\z([^"]\+\)\"" matchgroup=shHereDoc08 end="^\t*\z1$" 599 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc09 start="<<\s*\\\_$\_s*\z([^ \t|>]\+\)" matchgroup=shHereDoc09 end="^\z1$" contains=@shDblQuoteList 600 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc10 start="<<-\s*\\\_$\_s*\z([^ \t|>]\+\)" matchgroup=shHereDoc10 end="^\t*\z1$" contains=@shDblQuoteList 601 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc11 start="<<\s*\\\_$\_s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc11 end="^\z1$" 602 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc12 start="<<-\s*\\\_$\_s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc12 end="^\t*\z1$" 603 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc13 start="<<\s*\\\_$\_s*'\z([^']\+\)'" matchgroup=shHereDoc13 end="^\z1$" 604 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc14 start="<<-\s*\\\_$\_s*'\z([^']\+\)'" matchgroup=shHereDoc14 end="^\t*\z1$" 605 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc15 start="<<\s*\\\_$\_s*\"\z([^"]\+\)\"" matchgroup=shHereDoc15 end="^\z1$" 606 ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc16 start="<<-\s*\\\_$\_s*\"\z([^"]\+\)\"" matchgroup=shHereDoc16 end="^\t*\z1$" 607 608 609 " Here Strings: {{{1 610 " ============= 611 " available for: bash and ksh (except ksh88) but not if its a posix 612 if exists("b:is_bash") || ((exists("b:is_kornshell") && !exists("b:is_ksh88")) && !exists("b:is_posix")) 613 syn match shHereString "<<<" skipwhite nextgroup=shCmdParenRegion 614 endif 615 616 " Identifiers: {{{1 617 "============= 618 syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained 619 syn match shVariable "\<\h\w*\ze=" nextgroup=shVarAssign 620 if exists("b:is_bash") 621 " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". 622 syn region shArrayValue contained start="\[\%(..\{-}\]=\)\@=" end="\]=\@=" contains=@shArrayValueList nextgroup=shVarAssign 623 syn cluster shArrayValueList contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shEscape,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,bashSpecialVariables,shParenError 624 syn region shArrayRegion contained matchgroup=shShellVariables start="(" skip='\\\\\|\\.' end=")" contains=@shArrayValueList,shArrayValue,shComment 625 elseif (exists("b:is_kornshell") && !exists("b:is_ksh88")) 626 " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". 627 syn region shArrayValue contained start="\[\%(..\{-}\]=\)\@=" end="\]=\@=" contains=@shArrayValueList nextgroup=shVarAssign 628 syn cluster shArrayValueList contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shEscape,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,kshSpecialVariables,shParenError 629 syn region shArrayRegion contained matchgroup=shShellVariables start="(" skip='\\\\\|\\.' end=")" contains=@shArrayValueList,shArrayValue,shComment,shArrayRegion 630 endif 631 if exists("b:is_bash") || exists("b:is_kornshell") 632 syn match shVariable "\<\h\w*\%(\[..\{-}\]\)\=\ze\%([|^&*/%+-]\|[<^]<\|[>^]>\)\==" contains=shDerefVarArray nextgroup=shVarAssign 633 syn match shVarAssign contained "\%([|^&*/%+-]\|[<^]<\|[>^]>\)\==" nextgroup=shArrayRegion,shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar 634 else 635 syn match shVarAssign contained "=" nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar 636 endif 637 syn match shVar contained "\h\w*" 638 syn region shAtExpr contained start="@(" end=")" contains=@shIdList 639 if exists("b:is_bash") 640 syn match shSet "^\s*set\ze\s\+$" 641 syn region shSetList oneline matchgroup=shSet start="\<\%(declare\|local\|export\)\>\ze[/a-zA-Z_]\@!" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+#\|=" contains=@shIdList 642 syn region shSetList oneline matchgroup=shSet start="\<\%(set\|unset\)\>[/a-zA-Z_]\@!" end="\ze[;|#)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+=" contains=@shIdList nextgroup=shComment 643 elseif exists("b:is_kornshell") || exists("b:is_posix") 644 syn match shSet "^\s*set\ze\s\+$" 645 if exists("b:is_dash") 646 syn region shSetList oneline matchgroup=shSet start="\<\%(local\)\>\ze[/]\@!" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList 647 syn keyword shStatement chdir 648 endif 649 syn region shSetList oneline matchgroup=shSet start="\<\(export\)\>\ze[/]\@!" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList 650 syn region shSetList oneline matchgroup=shSet start="\<\%(set\|unset\>\)\ze[/a-zA-Z_]\@!" end="\ze[;|#)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList nextgroup=shComment 651 else 652 syn region shSetList oneline matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[/a-zA-Z_]\@!" end="\ze[;|#)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList 653 endif 654 655 " KornShell namespace: {{{1 656 if exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") 657 syn keyword shFunctionKey namespace skipwhite nextgroup=shNamespaceOne 658 endif 659 660 " Functions: {{{1 661 if !exists("b:is_posix") 662 syn match shFunctionKeyDelim "\s\+" contained transparent nextgroup=shDoError,shIfError,shFunctionNameCommentError,shFunctionTwo,shFunctionFour,shFunctionCmdTwo 663 syn match shFunctionKey "\<function\s\@=" nextgroup=shFunctionKeyDelim 664 endif 665 666 ShFoldFunctions syn region shFunctionExpr matchgroup=shFunctionExprRegion start="{" end="}" contains=@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment 667 ShFoldFunctions syn region shFunctionSubSh matchgroup=shFunctionSubShRegion start="(" end=")" contains=@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment 668 669 syn match shFunctionParens "()" contained 670 671 if exists("b:is_bash") 672 syn keyword shFunctionKey coproc 673 syn match shFunctionCmdOne "\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens 674 syn match shFunctionCmdTwo "\%#=1\%(\%(\<\k\+\>\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\s*\%(()\ze\)\=\_s*\%(\<\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" contained skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens 675 syn match shFunctionOne "\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 676 syn match shFunctionThree "\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens 677 " Proof against future changes by inducing priority-driven "backtracking" 678 " between shFunctionFour (goes before) and shFunctionTwo (goes after) so 679 " that e.g. "function f () {}" is still claimed by shFunctionTwo (observe 680 " "f[[:blank:]]()"). 681 syn match shFunctionFour "\%#=1\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\%(\%(\s*()\ze\)\=\)\@>\_s*((\@!" contained skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens 682 syn match shFunctionTwo "\%#=1\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\%(\%(\s*()\ze\)\=\)\@>\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 683 " Claim empty array assignments. 684 syn match shArrayEmptyDecl "\%#=1\ze\%(\<\h\w*=\)\@>()" transparent nextgroup=shVariable 685 " Claim commented out function declaration headers. 686 syn match shFunctionComment "^\s*\zs\ze#" transparent nextgroup=shComment 687 ShDefSynErrRule syn match shFunctionNameAssignError "\%#=1\%(\%(\<\h\w*\)\@>=\)\%(\%(\w\+\)\@>=\=\)\+()" skipwhite skipnl nextgroup=shExpr,shSubSh 688 ShDefSynErrRule syn match shFunctionNameCommentError "#" contained 689 elseif exists("b:is_ksh88") 690 " AT&T ksh88 691 syn match shFunctionCmdOne "^\s*\zs\h\w*\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens 692 syn match shFunctionOne "^\s*\zs\h\w*\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 693 syn match shFunctionTwo "\<\h\w*\>\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr 694 syn match shFunctionThree "^\s*\zs\h\w*\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens 695 elseif exists("b:is_mksh") 696 " MirBSD ksh is the wild west of absurd and abstruse function names... 697 syn match shFunctionCmdOne "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens 698 syn match shFunctionOne "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 699 syn match shFunctionTwo "\%#=1\%(\%(\<\w\+\|[@!+.%,:-]\+\)*[-A-Za-z_.%,0-9:]\)\@>\ze\s*\%(()\ze\)\=\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 700 syn match shFunctionThree "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens 701 elseif exists("b:is_kornshell") 702 " ksh93 703 syn match shFunctionCmdOne "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens 704 syn match shFunctionOne "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 705 syn match shFunctionTwo "\%(\<\h\+\|\.\)[A-Za-z_.0-9]*\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr 706 syn match shFunctionThree "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens 707 syn match shNamespaceOne "\<\h\w*\>\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr 708 else 709 syn match shFunctionCmdOne "^\s*\zs\h\w*\s*()\ze\_s*\%(for\|case\|if\|while\|until\)\>" skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens 710 syn match shFunctionCmdTwo "\<\h\w*\s*()\ze\_s*\%(for\|case\|if\|while\|until\)\>" contained skipwhite skipnl nextgroup=@shFunctionCmds contains=shFunctionParens 711 syn match shFunctionOne "^\s*\zs\h\w*\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 712 syn match shFunctionTwo "\<\h\w*\>\s*()\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr contains=shFunctionParens 713 syn match shFunctionThree "^\s*\zs\h\w*\s*()\ze\_s*(" skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens 714 syn match shFunctionFour "\<\h\w*\>\s*()\ze\_s*(" contained skipwhite skipnl nextgroup=shFunctionSubSh contains=shFunctionParens 715 endif 716 717 ShDefSynErrRule syn match shDoError "\<do\%(ne\)\=\s*()" 718 ShDefSynErrRule syn match shIfError "\<then\s*()" 719 ShDefSynErrRule syn match shIfError "\<else\s*()" 720 721 " Parameter Dereferencing: {{{1 722 " ======================== 723 ShDefSynErrRule syn match shDerefWordError "[^}$[~]" contained 724 syn match shDerefSimple "\$\%(\h\w*\|\d\)" nextgroup=@shNoZSList 725 if exists("b:is_kornshell") && !exists("b:is_ksh88") 726 if exists("b:is_mksh") 727 syn region shDeref matchgroup=PreProc start="\${\ze[^ \t\n|]" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart 728 elseif exists("b:generic_korn") 729 syn region shDeref matchgroup=PreProc start="\${\ze[^ \t\n<|]" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart 730 else 731 syn region shDeref matchgroup=PreProc start="\${\ze[^ \t\n<]" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart 732 endif 733 elseif exists("b:is_bash") 734 syn region shDeref matchgroup=PreProc start="\${\ze[^ \t\n|]" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart 735 else 736 syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart 737 endif 738 syn match shDerefSimple "\$[-#*@!?]" nextgroup=@shNoZSList 739 syn match shDerefSimple "\$\$" nextgroup=@shNoZSList 740 syn match shDerefSimple "\${\d}" nextgroup=@shNoZSList nextgroup=shSpecialStart 741 if exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix") 742 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList nextgroup=@shSpecialNoZS,shSpecialStart 743 syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList nextgroup=@shSpecialNoZS,shSpecialStart 744 endif 745 746 " ksh: ${.sh.*} variables: {{{1 747 " ======================================== 748 if exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") 749 syn match shDerefVar contained "\.\+" nextgroup=@shDerefVarList 750 syn region shDeref matchgroup=PreProc start="\${\ze[\.]" end="}" contains=@shDerefVarList,shDerefPSR,shDerefPPS 751 endif 752 753 " ksh: ${!var[*]} array index list syntax: {{{1 754 " ======================================== 755 if (exists("b:is_kornshell") && !exists("b:is_ksh88")) || exists("b:is_posix") 756 syn region shDeref matchgroup=PreProc start="\${!" end="}" contains=@shDerefVarArray 757 endif 758 759 " bash: ${!prefix*} and ${#parameter}: {{{1 760 " ==================================== 761 if exists("b:is_bash") 762 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOffset 763 syn match shDerefVar contained "{\@<=!\h\w*" nextgroup=@shDerefVarList 764 syn match shDerefSpecial contained "\({!\)\@<=[[:alnum:]*#@_]\+" nextgroup=@shDerefVarList,shDerefOp 765 endif 766 if (exists("b:is_kornshell") && !exists("b:is_ksh88")) 767 syn match shDerefVar contained "{\@<=!\h\w*[[:alnum:]_.]*" nextgroup=@shDerefVarList 768 syn match shDerefSpecial contained "\({!\)\@<=[[:alnum:]*#@_]\+" nextgroup=@shDerefVarList,shDerefOp 769 endif 770 771 syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOffset,shDerefOpError 772 syn match shDerefSpecial contained "\({[#]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp 773 syn match shDerefVar contained "{\@<=\h\w*" nextgroup=@shDerefVarList 774 syn match shDerefVar contained '\d' nextgroup=@shDerefVarList 775 if exists("b:is_kornshell") || exists("b:is_posix") 776 syn match shDerefVar contained "{\@<=\h\w*[[:alnum:]_.]*" nextgroup=@shDerefVarList 777 endif 778 779 " sh ksh bash : ${var[... ]...} array reference: {{{1 780 syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError,shDerefOffset 781 782 " Special ${parameter OPERATOR word} handling: {{{1 783 " sh ksh bash : ${parameter:-word} word is default value 784 " sh ksh bash : ${parameter:=word} assign word as default value 785 " sh ksh bash : ${parameter:?word} display word if parameter is null 786 " sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing 787 " ksh bash : ${parameter#pattern} remove small left pattern 788 " ksh bash : ${parameter##pattern} remove large left pattern 789 " ksh bash : ${parameter%pattern} remove small right pattern 790 " ksh bash : ${parameter%%pattern} remove large right pattern 791 " ksh bash : ${parameter^pattern} Case modification 792 " ksh bash : ${parameter^^pattern} Case modification 793 " ksh bash : ${parameter,pattern} Case modification 794 " ksh bash : ${parameter,,pattern} Case modification 795 " bash : ${@:start:qty} display command line arguments from start to start+qty-1 (inferred) 796 " bash : ${parameter@operator} transforms parameter (operator∈[uULqEPARa]) 797 syn cluster shDerefPatternList contains=shDerefPattern,shDerefString 798 ShDefSynErrRule syn match shDerefOpError contained ":[[:punct:]]" 799 syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList 800 syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList 801 if exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix") 802 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList 803 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList 804 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern skipnl 805 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern 806 " Match parametric bracket expressions with a leading whitespace character. 807 syn region shDerefPattern contained matchgroup=shBracketExprDelim start="\[" end="\]" contains=@shBracketExprList,shDoubleQuote nextgroup=shDerefPattern 808 call s:GenerateBracketExpressionItems({'itemGroup': 'shDerefPattern', 'bracketGroup': 'shBracketExprDelim', 'extraArgs': 'contained nextgroup=shDerefPattern'}) 809 syn match shDerefEscape contained '\%(\\\\\)*\\.' 810 endif 811 if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") && !exists("b:is_ksh93u") && !exists("b:is_ksh2020")) 812 syn match shDerefOp contained "[,^]\{1,2}" nextgroup=@shDerefPatternList 813 endif 814 if exists("b:is_bash") 815 syn match shDerefOp contained "@[uULQEPAKa]" 816 endif 817 syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ 818 syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial 819 syn match shDerefString contained "\\["']" nextgroup=shDerefPattern 820 821 if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88")) || exists("b:is_posix") 822 " bash ksh posix : ${parameter:offset} 823 " bash ksh posix : ${parameter:offset:length} 824 syn region shDerefOffset contained start=':[^-=?+]' end='\ze:' end='\ze}' contains=shDeref,shDerefSimple,shDerefEscape nextgroup=shDerefLen,shDeref,shDerefSimple 825 syn region shDerefOffset contained start=':\s-' end='\ze:' end='\ze}' contains=shDeref,shDerefSimple,shDerefEscape nextgroup=shDerefLen,shDeref,shDerefSimple 826 syn match shDerefLen contained ":[^}]\+" contains=shDeref,shDerefSimple,shArithmetic 827 endif 828 829 if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88")) 830 " bash ksh : ${parameter/pattern/string} 831 " bash ksh : ${parameter//pattern/string} 832 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft 833 syn region shDerefPPSleft contained start='.' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' end='"' nextgroup=shDerefPPSright contains=@shPPSLeftList 834 syn region shDerefPPSright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}' contains=@shPPSRightList 835 836 " bash ksh : ${parameter/#pattern/string} 837 " bash ksh : ${parameter/%pattern/string} 838 syn match shDerefPSR contained '/[#%]' nextgroup=shDerefPSRleft,shDoubleQuote,shSingleQuote 839 syn region shDerefPSRleft contained start='[^"']' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPSRright contains=shBracketExpr 840 syn region shDerefPSRright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}' 841 endif 842 843 " Arithmetic Parenthesized Expressions: {{{1 844 "syn region shParen matchgroup=shArithRegion start='[^$]\zs(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList 845 syn region shParen matchgroup=shArithRegion start='\$\@!(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList 846 847 " Additional sh Keywords: {{{1 848 " =================== 849 " builtins: 850 syn keyword shStatement bg break cd continue command eval exec exit export fc getopts hash jobs local printf read readonly return shift times trap type ulimit umask unalias wait 851 " external programs: 852 syn keyword shStatement basename cat chgrp chmod chown cksum clear cmp comm cp cut date dirname du egrep expr false fgrep find fmt fold getconf grep head iconv id join kill killall less ln login logname ls md5sum mkdir mkfifo mknod mktemp mv newgrp nice nohup od paste pathchk printenv pwd readlink realpath rename rev rm rmdir sed sha1sum sha224sum sha256sum sha384sum sha512sum sleep sort strip stty sum sync tail tee test tput tr true tty uname uniq wc which xargs 853 syn keyword shConditional contained elif else then 854 ShDefSynErrRule syn keyword shCondError elif else then 855 856 " Synchronization: {{{1 857 " ================ 858 if !exists("g:sh_minlines") 859 let s:sh_minlines = 200 860 else 861 let s:sh_minlines= g:sh_minlines 862 endif 863 if !exists("g:sh_maxlines") 864 let s:sh_maxlines = 2*s:sh_minlines 865 if s:sh_maxlines < 25 866 let s:sh_maxlines= 25 867 endif 868 else 869 let s:sh_maxlines= g:sh_maxlines 870 endif 871 exec "syn sync minlines=" . s:sh_minlines . " maxlines=" . s:sh_maxlines 872 syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>" 873 syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>" 874 syn sync match shDoSync grouphere shDo "\<do\>" 875 syn sync match shDoSync groupthere shDo "\<done\>" 876 syn sync match shForSync grouphere shFor "\<for\>" 877 syn sync match shForSync groupthere shFor "\<in\>" 878 syn sync match shIfSync grouphere shIf "\<if\>" 879 syn sync match shIfSync groupthere shIf "\<fi\>" 880 syn sync match shUntilSync grouphere shRepeat "\<until\>" 881 syn sync match shWhileSync grouphere shRepeat "\<while\>" 882 883 " Default Highlighting: {{{1 884 " ===================== 885 if !exists("skip_sh_syntax_inits") 886 hi def link shArithRegion shShellVariables 887 hi def link shArrayValue shDeref 888 hi def link shAstQuote shDoubleQuote 889 hi def link shAtExpr shSetList 890 hi def link shBkslshSnglQuote shSingleQuote 891 hi def link shBkslshDblQuote shDOubleQuote 892 hi def link shBeginHere shRedir 893 hi def link shCaseBar shConditional 894 hi def link shCaseCommandSub shCommandSub 895 hi def link shCaseDoubleQuote shDoubleQuote 896 hi def link shCaseIn shConditional 897 hi def link shQuote shOperator 898 hi def link shCaseSingleQuote shSingleQuote 899 hi def link shCaseStart shConditional 900 hi def link shCmdSubRegion shShellVariables 901 hi def link shColon shComment 902 hi def link shDerefOp shOperator 903 hi def link shDerefPOL shDerefOp 904 hi def link shDerefPPS shDerefOp 905 hi def link shDerefPSR shDerefOp 906 hi def link shDeref shShellVariables 907 hi def link shDerefDelim shOperator 908 hi def link shDerefSimple shDeref 909 hi def link shDerefSpecial shDeref 910 hi def link shDerefString shDoubleQuote 911 hi def link shDerefVar shDeref 912 hi def link shDoubleQuote shString 913 hi def link shEcho shString 914 hi def link shEchoDelim shOperator 915 hi def link shEchoQuote shString 916 hi def link shForPP shLoop 917 hi def link shEmbeddedEcho shString 918 hi def link shEscape shCommandSub 919 hi def link shExDoubleQuote shDoubleQuote 920 hi def link shExSingleQuote shSingleQuote 921 hi def link shHereDoc shString 922 hi def link shHereString shRedir 923 hi def link shHerePayload shHereDoc 924 hi def link shLoop shStatement 925 hi def link shSpecialNxt shSpecial 926 hi def link shNoQuote shDoubleQuote 927 hi def link shOption shCommandSub 928 hi def link shPattern shString 929 hi def link shParen shArithmetic 930 hi def link shPosnParm shShellVariables 931 hi def link shQuickComment shComment 932 hi def link shBQComment shComment 933 hi def link shRange shOperator 934 hi def link shRedir shOperator 935 hi def link shSetListDelim shOperator 936 hi def link shSetOption shOption 937 hi def link shSingleQuote shString 938 hi def link shSource shOperator 939 hi def link shStringSpecial shSpecial 940 hi def link shSpecialStart shSpecial 941 hi def link shSubShRegion shOperator 942 hi def link shTestOpr shConditional 943 hi def link shTestPattern shString 944 hi def link shTestDoubleQuote shString 945 hi def link shTestSingleQuote shString 946 hi def link shTouchCmd shStatement 947 hi def link shVariable shSetList 948 hi def link shWrapLineOperator shOperator 949 950 if exists("b:is_bash") 951 hi def link bashAdminStatement shStatement 952 hi def link bashSpecialVariables shShellVariables 953 hi def link bashStatement shStatement 954 hi def link shCharClass shSpecial 955 hi def link shDerefOffset shDerefOp 956 hi def link shDerefLen shDerefOffset 957 endif 958 if exists("b:is_kornshell") || exists("b:is_posix") 959 hi def link kshSpecialVariables shShellVariables 960 hi def link kshStatement shStatement 961 endif 962 963 ShLinkSynErrGroup hi def link shCaseError Error 964 ShLinkSynErrGroup hi def link shCondError Error 965 ShLinkSynErrGroup hi def link shCurlyError Error 966 ShLinkSynErrGroup hi def link shDerefOpError Error 967 ShLinkSynErrGroup hi def link shDerefWordError Error 968 ShLinkSynErrGroup hi def link shDoError Error 969 ShLinkSynErrGroup hi def link shEsacError Error 970 ShLinkSynErrGroup hi def link shIfError Error 971 ShLinkSynErrGroup hi def link shInError Error 972 ShLinkSynErrGroup hi def link shParenError Error 973 ShLinkSynErrGroup hi def link shTestError Error 974 if exists("b:is_bash") 975 ShLinkSynErrGroup hi def link shFunctionNameAssignError Error 976 ShLinkSynErrGroup hi def link shFunctionNameCommentError Error 977 endif 978 if exists("b:is_kornshell") || exists("b:is_posix") 979 ShLinkSynErrGroup hi def link shDTestError Error 980 endif 981 982 hi def link shArithmetic Special 983 hi def link shBracketExprDelim Delimiter 984 hi def link shCharClass Identifier 985 hi def link shCollSymb shCharClass 986 hi def link shEqClass shCharClass 987 hi def link shSnglCase Statement 988 hi def link shCommandSub Special 989 hi def link shCommandSubBQ shCommandSub 990 hi def link shSubshare shCommandSub 991 hi def link shValsub shCommandSub 992 hi def link shComment Comment 993 hi def link shConditional Conditional 994 hi def link shCtrlSeq Special 995 hi def link shExprRegion Delimiter 996 hi def link shFunctionKey Keyword 997 hi def link shFunctionParens Delimiter 998 hi def link shFunctionOne Function 999 hi def link shFunctionTwo shFunctionOne 1000 hi def link shFunctionThree shFunctionOne 1001 hi def link shFunctionFour shFunctionOne 1002 hi def link shFunctionCmdOne shFunctionOne 1003 hi def link shFunctionCmdTwo shFunctionOne 1004 hi def link shFunctionExprRegion shExprRegion 1005 hi def link shFunctionSubShRegion shSubShRegion 1006 hi def link shNamespaceOne Function 1007 hi def link shNumber Number 1008 hi def link shOperator Operator 1009 hi def link shRepeat Repeat 1010 hi def link shSet Statement 1011 hi def link shSetList Identifier 1012 hi def link shShellVariables PreProc 1013 hi def link shSpecial Special 1014 hi def link shSpecialDQ Special 1015 hi def link shSpecialSQ Special 1016 hi def link shSpecialNoZS shSpecial 1017 hi def link shStatement Statement 1018 hi def link shString String 1019 hi def link shTodo Todo 1020 hi def link shAlias Identifier 1021 hi def link shHereDoc01 shRedir 1022 hi def link shHereDoc02 shRedir 1023 hi def link shHereDoc03 shRedir 1024 hi def link shHereDoc04 shRedir 1025 hi def link shHereDoc05 shRedir 1026 hi def link shHereDoc06 shRedir 1027 hi def link shHereDoc07 shRedir 1028 hi def link shHereDoc08 shRedir 1029 hi def link shHereDoc09 shRedir 1030 hi def link shHereDoc10 shRedir 1031 hi def link shHereDoc11 shRedir 1032 hi def link shHereDoc12 shRedir 1033 hi def link shHereDoc13 shRedir 1034 hi def link shHereDoc14 shRedir 1035 hi def link shHereDoc15 shRedir 1036 hi def link shHereDoc16 shRedir 1037 endif 1038 1039 " Delete shell commands {{{1 1040 " ===================== 1041 delc ShFoldFunctions 1042 delc ShFoldHereDoc 1043 delc ShFoldIfDoFor 1044 delc ShLinkSynErrGroup 1045 delc ShDefSynErrRule 1046 1047 " Delete shell functions {{{1 1048 " ====================== 1049 delfun s:ScanAndCondExecSynErrCmd 1050 delfun s:GenerateBracketExpressionItems 1051 1052 " Set Current Syntax: {{{1 1053 " =================== 1054 if exists("b:is_bash") 1055 let b:current_syntax = "bash" 1056 elseif exists("b:is_kornshell") 1057 let b:current_syntax = "ksh" 1058 elseif exists("b:is_posix") 1059 let b:current_syntax = "posix" 1060 else 1061 let b:current_syntax = "sh" 1062 endif 1063 1064 " vim: ts=16 fdm=marker