robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
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 13if exists ( "b:current_syntax" ) 14finish 15endif 16 17" Ensure this is set unless we find another shell 18let b: is_sh = 1 19 20" If the shell script itself specifies which shell to use, use it 21let s: shebang = getline ( 1 ) 22 23if s: shebang =~ '^#!.\{-2,}\<ksh\>' 24" The binary is too ambiguous (i.e. '/bin/ksh' or some such). 25let b: is_kornshell = 1 26let b: generic_korn = 1 27elseif s: shebang =~ '^#!.\{-2,}\<ksh93u\+\>' 28" ksh93u+ (or 93u-) release (still much too common to encounter) 29let b: is_kornshell = 1 30let b: is_ksh93u = 1 31elseif s: shebang =~ '^#!.\{-2,}\<ksh93v\>' 32" ksh93v- alpha or beta 33let b: is_kornshell = 1 34let b: is_ksh93v = 1 35elseif s: shebang =~ '^#!.\{-2,}\<ksh93\>' 36" Could be any ksh93 release 37let b: is_kornshell = 1 38let b: is_ksh93 = 1 39elseif s: shebang =~ '^#!.\{-2,}\<ksh2020\>' 40let b: is_kornshell = 1 41let b: is_ksh2020 = 1 42elseif s: shebang =~ '^#!.\{-2,}\<ksh88\>' 43" The actual AT&T ksh88 and its feature set is assumed. 44let b: is_kornshell = 1 45let b: is_ksh88 = 1 46elseif s: shebang =~ '^#!.\{-2,}\<mksh\>' 47" MirBSD Korn Shell 48let b: is_kornshell = 1 49let b: is_mksh = 1 50elseif s: shebang =~ '^#!.\{-2,}\<bash\>' 51let b: is_bash = 1 52elseif s: shebang =~ '^#!.\{-2,}\<dash\>' 53let 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. 61elseif ! exists ( "b:is_kornshell" ) && ! exists ( "b:is_bash" ) && ! exists ( "b:is_posix" ) && ! exists ( "b:is_dash" ) 62if exists ( "g:is_kornshell" ) 63let b: is_kornshell = 1 64let b: generic_korn = 1 65elseif exists ( "g:is_bash" ) 66let b: is_bash = 1 67elseif exists ( "g:is_dash" ) 68let b: is_dash = 1 69elseif exists ( "g:is_posix" ) 70let b: is_posix = 1 71elseif exists ( "g:is_sh" ) 72let b: is_sh = 1 73else 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. 77let s: shell = "" 78if executable ( "/bin/sh" ) 79let s: shell = resolve ( "/bin/sh" ) 80elseif executable ( "/usr/bin/sh" ) 81let s: shell = resolve ( "/usr/bin/sh" ) 82endif 83if s: shell =~ '\<ksh\>' 84" The binary is too ambiguous (i.e. '/bin/ksh' or some such). 85let b: is_kornshell = 1 86let b: generic_korn = 1 87elseif s: shell =~ '\<ksh93u\+\>' 88" ksh93u+ (or 93u-) release (still much too common to encounter) 89let b: is_kornshell = 1 90let b: is_ksh93u = 1 91elseif s: shell =~ '\<ksh93v\>' 92" ksh93v- alpha or beta 93let b: is_kornshell = 1 94let b: is_ksh93v = 1 95elseif s: shell =~ '\<ksh93\>' 96" Could be any ksh93 release 97let b: is_kornshell = 1 98let b: is_ksh93 = 1 99elseif s: shebang =~ '\<ksh2020\>' 100let b: is_kornshell = 1 101let b: is_ksh2020 = 1 102elseif s: shell =~ '\<ksh88\>' 103" The actual AT&T ksh88 and its feature set is assumed. 104let b: is_kornshell = 1 105let b: is_ksh88 = 1 106elseif s: shell =~ '\<mksh\>' 107" MirBSD Korn Shell 108let b: is_kornshell = 1 109let b: is_mksh = 1 110elseif s: shell =~ '\<bash\>' 111let b: is_bash = 1 112elseif s: shell =~ '\<dash\>' 113let b: is_dash = 1 114else 115let b: is_posix = 1 116endif 117unlet s: shell 118endif 119endif 120 121unlet s: shebang 122 123" if b:is_dash, set b:is_posix too 124if exists ( "b:is_dash" ) 125let b: is_posix = 1 126endif 127 128if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 129if exists ( "b:is_sh" ) 130unlet b: is_sh 131endif 132endif 133 134" set up default g:sh_fold_enabled {{{1 135" ================================ 136if ! exists ( "g:sh_fold_enabled" ) 137let g: sh_fold_enabled = 0 138elseif g: sh_fold_enabled != 0 && ! has ( "folding" ) 139echomsg "Ignoring g:sh_fold_enabled=" . g: sh_fold_enabled . "; need to re-compile vim for +fold support" 140let g: sh_fold_enabled = 0 141endif 142let s: sh_fold_functions = and ( g: sh_fold_enabled , 1 ) 143let s: sh_fold_heredoc = and ( g: sh_fold_enabled , 2 ) 144let s: sh_fold_ifdofor = and ( g: sh_fold_enabled , 4 ) 145if 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 149setl fdm = syntax 150endif 151 152" set up the syntax-highlighting for iskeyword 153if ( v: version == 704 && has ( "patch-7.4.1142" )) || v: version > 704 154if ! exists ( "g:sh_syntax_isk" ) || ( exists ( "g:sh_syntax_isk" ) && g: sh_syntax_isk ) 155if exists ( "b:is_bash" ) 156exe "syn iskeyword " .& iskeyword . ",-,:" 157elseif exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" ) && ! exists ( "b:is_mksh" ) 158exe "syn iskeyword " .& iskeyword . ",-,." 159else 160exe "syn iskeyword " .& iskeyword . ",-" 161endif 162endif 163endif 164 165" Set up folding commands for shell {{{1 166" ================================= 167if exists ( ":ShFoldFunctions" ) == 2 168delc ShFoldFunctions 169endif 170if exists ( ":ShFoldIfHereDoc" ) == 2 171delc ShFoldHereDoc 172endif 173if exists ( ":ShFoldIfDoFor" ) == 2 174delc ShFoldIfDoFor 175endif 176if s: sh_fold_functions 177com ! -nargs = * ShFoldFunctions <args> fold 178else 179com ! -nargs = * ShFoldFunctions <args> 180endif 181if s: sh_fold_heredoc 182com ! -nargs = * ShFoldHereDoc <args> fold 183else 184com ! -nargs = * ShFoldHereDoc <args> 185endif 186if s: sh_fold_ifdofor 187com ! -nargs = * ShFoldIfDoFor <args> fold 188else 189com ! -nargs = * ShFoldIfDoFor <args> 190endif 191 192" Set up syntax error commands for shell {{{1 193" ====================================== 194if exists ( "g:sh_no_error_rules" ) && type ( g: sh_no_error_rules ) == type ([]) 195fun ! s: ScanAndCondExecSynErrCmd ( idx , cmd ) abort 196let parts = matchlist ( a: cmd , '\(\(\S\+\)\s\+\(\S\+\)\s*\)\{2}' ) 197" Do nothing for matchable names listed in "g:sh_no_error_rules". 198if len ( parts ) < a: idx || index ( g: sh_no_error_rules , parts [ a: idx ]) < 0 199exec a: cmd 200endif 201endfun 202elseif exists ( "g:sh_no_error" ) 203fun ! s: ScanAndCondExecSynErrCmd ( _ , __ ) abort 204endfun 205else 206fun ! s: ScanAndCondExecSynErrCmd ( _ , cmd ) abort 207exec a: cmd 208endfun 209endif 210 211" Read shFooError from "syn match shFooError '<pattern>'" etc. 212com ! -nargs = + ShDefSynErrRule call s:ScanAndCondExecSynErrCmd(2, <q-args>) 213" Read shFooError from "hi def link shFooError Error". 214com ! -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"). 224fun ! s: GenerateBracketExpressionItems ( dict ) abort 225let itemGroup = a: dict . itemGroup 226let bracketGroup = a: dict . bracketGroup 227let invGroup = itemGroup . 'Inv' 228let skipLeftBracketGroup = itemGroup . 'SkipLeftBracket' 229let skipRightBracketGroup = itemGroup . 'SkipRightBracket' 230let extraArgs = has_key ( a: dict , 'extraArgs' ) ? a: dict . extraArgs : '' 231 232" Make the leading "[!^]" stand out in a NON-matching expression. 233exec 'syn match ' . invGroup . ' contained "\[\@<=[!^]"' 234 235" Set up indirections for unbalanced-bracket highlighting. 236exec 'syn region ' . skipRightBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" matchgroup=shCollSymb end="\[\.[^]]\{-}\][^]]\{-}\.\]" matchgroup=' . itemGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . invGroup 237exec 'syn region ' . skipLeftBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" skip="[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\%(\[[:.=]\@!\)\@=" matchgroup=' . itemGroup . ' end="\[[:.=]\@!" contains=@shBracketExprList,shDoubleQuote,' . invGroup 238 239" Look for a general matching expression. 240exec 'syn region ' . itemGroup . ' matchgroup=' . bracketGroup . ' start="\[\S\@=" end="\]" contains=@shBracketExprList,shDoubleQuote ' . extraArgs 241" Look for a general NON-matching expression. 242exec '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). 247exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipRightBracketGroup . ' ' . extraArgs 248" Strive to handle "[]...[]" etc. 249exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\[[:.=]\@!" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipLeftBracketGroup . ' ' . extraArgs 250 251if ! exists ( "g:skip_sh_syntax_inits" ) 252exec 'hi def link ' . skipLeftBracketGroup . ' ' . itemGroup 253exec 'hi def link ' . skipRightBracketGroup . ' ' . itemGroup 254exec 'hi def link ' . invGroup . ' Underlined' 255endif 256endfun 257 258call s: GenerateBracketExpressionItems ({ 'itemGroup' : 'shBracketExpr' , 'bracketGroup' : 'shBracketExprDelim' }) 259 260" sh syntax is case sensitive {{{1 261syn case match 262 263" Clusters: contains=@... clusters {{{1 264"================================== 265syn cluster shErrorList contains = shDoError , shIfError , shInError , shCaseError , shEsacError , shCurlyError , shParenError , shTestError , shOK 266if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 267syn cluster ErrorList add = shDTestError 268endif 269syn 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 270syn cluster shArithList contains = @shArithParenList , shParenError 271syn cluster shBracketExprList contains = shCharClassOther , shCharClass , shCollSymb , shEqClass 272syn cluster shCaseEsacList contains = shCaseStart , shCaseLabel , shCase , shCaseBar , shCaseIn , shComment , shDeref , shDerefSimple , shCaseCommandSub , shCaseExSingleQuote , shCaseSingleQuote , shCaseDoubleQuote , shCtrlSeq , @shErrorList , shStringSpecial , shCaseRange 273syn 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 274if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 275syn cluster shCaseList add = shForPP , shDblParen 276endif 277syn 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 278syn 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 280syn cluster shDblQuoteList contains = shArithmetic , shCommandSub , shCommandSubBQ , shSubshare , shValsub , shDeref , shDerefSimple , shEscape , shPosnParm , shCtrlSeq , shSpecial , shSpecialDQ 281syn cluster shDerefList contains = shDeref , shDerefSimple , shDerefVar , shDerefSpecial , shDerefWordError , shDerefPSR , shDerefPPS 282syn cluster shDerefVarList contains = shDerefOffset , shDerefOp , shDerefVarArray , shDerefOpError 283syn cluster shEchoList contains = shArithmetic , shBracketExpr , shCommandSub , shCommandSubBQ , shDerefVarArray , shSubshare , shValsub , shDeref , shDerefSimple , shEscape , shExSingleQuote , shExDoubleQuote , shSingleQuote , shDoubleQuote , shCtrlSeq , shEchoQuote 284syn cluster shExprList1 contains = shBracketExpr , shNumber , shOperator , shExSingleQuote , shExDoubleQuote , shSingleQuote , shDoubleQuote , shExpr , shDblBrace , shDeref , shDerefSimple , shCtrlSeq 285syn cluster shExprList2 contains = @shExprList1 , @shCaseList , shTest , shFunctionNameAssignError 286syn cluster shFunctionCmds contains = shFor , shCaseEsac , shIf , shRepeat , shDblBrace , shDblParen 287if exists ( "b:is_ksh88" ) || exists ( "b:is_mksh" ) 288" Offer "shFunctionCmds" as is. 289elseif exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 290syn cluster shFunctionCmds add = shForPP 291else 292syn cluster shFunctionCmds remove = shDblBrace , shDblParen 293endif 294syn cluster shFunctionDefList contains = shDoError , shIfError , shFunctionKey , shFunctionOne , shFunctionThree , shFunctionCmdOne 295syn cluster shFunctionList contains = shBracketExpr , @shCommandSubList , shCaseEsac , shColon , shComment , shDo , shEcho , shExpr , shFor , shHereDoc , shIf , shOption , shHereString , shRedir , shSetList , shSource , shStatement , shVariable , shOperator , shCtrlSeq , @shFunctionDefList 296if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 297syn cluster shFunctionList add = shRepeat , shDblBrace , shDblParen , shForPP 298syn cluster shDerefList add = shCommandSubList , shEchoDeref 299endif 300syn cluster shHereBeginList contains = @shCommandSubList 301syn cluster shHereList contains = shBeginHere , shHerePayload 302syn cluster shHereListDQ contains = shBeginHere , @shDblQuoteList , shHerePayload 303syn 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 304syn cluster shIfList contains = @shLoopList , shDblBrace , shDblParen , @shFunctionDefList 305syn cluster shLoopList contains = @shCaseList , @shErrorList , shCaseEsac , shConditional , shDblBrace , shExpr , shFor , shIf , shOption , shSet , shTest , shTestOpr , shTouch 306if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 307syn cluster shLoopList add = shForPP , shDblParen 308endif 309syn 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 310syn cluster shPPSRightList contains = shDeref , shDerefSimple , shEscape , shPosnParm 311syn 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 312syn cluster shTestList contains = shArithmetic , shBracketExpr , shCommandSub , shCommandSubBQ , shSubshare , shValsub , shCtrlSeq , shDeref , shDerefSimple , shDoubleQuote , shSpecialDQ , shExDoubleQuote , shExpr , shExSingleQuote , shNumber , shOperator , shSingleQuote , shTest , shTestOpr 313syn cluster shNoZSList contains = shSpecialNoZS 314syn 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 319if ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" )) 320syn region shEcho matchgroup = shStatement start = "\<echo\> "skip = "\\$ "matchgroup = shEchoDelim end = "$ "matchgroup = NONE end = "[ <>;&|()`} ] "me= e-1end = "\d [ <> ] "me= e-2end = "# "me= e-1end = "\ze [ \t\n; ] } "contains = @shEchoList skipwhite nextgroup = shQuickComment 321syn region shEcho matchgroup = shStatement start = "\<print\> "skip = "\\$ "matchgroup = shEchoDelim end = "$ "matchgroup = NONE end = "[ <>;&|()`} ] "me= e-1end = "\d [ <> ] "me= e-2end = "# "me= e-1end = "\ze [ \t\n; ] } "contains = @shEchoList skipwhite nextgroup = shQuickComment 322else 323syn region shEcho matchgroup = shStatement start = "\<echo\> "skip = "\\$ "matchgroup = shEchoDelim end = "$ "matchgroup = NONE end = "[ <>;&|()` ] "me= e-1end = "\d [ <> ] "me= e-2end = "# "me= e-1contains = @shEchoList skipwhite nextgroup = shQuickComment 324syn region shEcho matchgroup = shStatement start = "\<print\> "skip = "\\$ "matchgroup = shEchoDelim end = "$ "matchgroup = NONE end = "[ <>;&|()` ] "me= e-1end = "\d [ <> ] "me= e-2end = "# "me= e-1contains = @shEchoList skipwhite nextgroup = shQuickComment 325endif 326if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) || exists ( "b:is_posix" ) 327syn region shEchoDeref contained matchgroup = shStatement start = "\<echo\> "skip = "\\$ "matchgroup = shEchoDelim end = "$ "end = "[ <>;&|()`} ] "me= e-1end = "\d [ <> ] "me= e-2end = "# "me= e-1contains = @shEchoList skipwhite nextgroup = shQuickComment 328syn region shEchoDeref contained matchgroup = shStatement start = "\<print\> "skip = "\\$ "matchgroup = shEchoDelim end = "$ "end = "[ <>;&|()`} ] "me= e-1end = "\d [ <> ] "me= e-2end = "# "me= e-1contains = @shEchoList skipwhite nextgroup = shQuickComment 329endif 330syn match shEchoQuote contained '\%(\\\\\) * \\ [ "`'() ] ' 331 332" This must be after the strings, so that ... \" will be correct 333syn region shEmbeddedEcho contained matchgroup = shStatement start = "\<print\> "skip = "\\$ "matchgroup = shEchoDelim end = "$ "matchgroup = NONE end = "[ <>;&|`) ] "me= e-1end = "\d [ <> ] "me= e-2end = "\s# "me= e-2contains = shBracketExpr , shNumber , shExSingleQuote , shSingleQuote , shDeref , shDerefSimple , shSpecialVar , shOperator , shExDoubleQuote , shDoubleQuote , shCtrlSeq 334 335" Alias: {{{1 336" ===== 337if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) || exists ( "b:is_posix" ) 338syn match shStatement "\<alias\> " 339syn region shAlias matchgroup = shStatement start = "\<alias\>\s\+\(\h [ -._[:alnum: ] ] * \)\@= "skip = "\\$ "end = "\>\|` " 340syn region shAlias matchgroup = shStatement start = "\<alias\>\s\+\(\h [ -._[:alnum: ] ] * =\)\@= "skip = "\\$ "end = "= " 341 342" Touch: {{{1 343" ===== 344syn match shTouch '\<touch\> [ ^;# ] * 'skipwhite nextgroup = shComment contains = shTouchCmd , shDoubleQuote , shSingleQuote , shDeref , shDerefSimple , shExpr 345syn match shTouchCmd '\<touch\> 'contained 346endif 347 348" Error Codes: {{{1 349" ============ 350ShDefSynErrRule syn match shDoError"\<done\>" 351ShDefSynErrRule syn match shIfError"\<fi\>" 352ShDefSynErrRule syn match shInError"\<in\>" 353ShDefSynErrRule syn match shCaseError";;" 354ShDefSynErrRule syn match shEsacError"\<esac\>" 355ShDefSynErrRule syn match shCurlyError"}" 356ShDefSynErrRule syn match shParenError")" 357ShDefSynErrRule syn match shOK'\.\%(done\|fi\|in\|esac\)' 358if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 359ShDefSynErrRule syn match shDTestError"]]" 360endif 361ShDefSynErrRule syn match shTestError"]" 362 363" Options: {{{1 364" ==================== 365syn match shOption "\s\zs [ -+ ][ -_a-zA-Z#@0-9 ] \+ " 366syn match shOption "\s\zs-- [ ^ \t$=`'"|); ] \+ " 367 368" File Redirection Highlighted As Operators: {{{1 369"=========================================== 370syn match shRedir "\d\=>\(& [ -0-9 ] \)\= " 371syn match shRedir "\d\=>>-\= " 372syn match shRedir "\d\=<\(& [ -0-9 ] \)\= " 373syn match shRedir "\d<<-\= " 374 375" Operators: {{{1 376" ========== 377syn match shOperator "<<\|>> "contained 378syn match shOperator "[ !&;| ] "contained 379syn match shOperator "[ -=/*+% ] \== "skipwhite nextgroup = shPattern 380syn match shPattern "\<\S\+\())\)\@= "contained contains = shExSingleQuote , shSingleQuote , shExDoubleQuote , shDoubleQuote , shDeref 381 382" Subshells: {{{1 383" ========== 384syn region shExpr transparent matchgroup = shExprRegion start = "{ "end = "} "contains = @shExprList2 nextgroup = shSpecialNxt 385syn region shSubSh transparent matchgroup = shSubShRegion start = "[ ^( ] \zs( "end = ") "contains = @shSubShList nextgroup = shSpecialNxt 386 387" Tests: {{{1 388"======= 389syn region shExpr matchgroup = shRange start = "\[\s\@= "skip = +\\\\\|\\$\|\[ +end = "\] "contains = @shTestList , shSpecial 390syn region shTest transparent matchgroup = shStatement start = "\<test\s "skip = +\\\\\|\\$ +matchgroup = NONE end = "[ ;&| ] "me= e-1end = "$ "contains = @shExprList1 391syn region shNoQuote start = '\S 'skip = '\%(\\\\\) * \\. 'end = '\ze\s 'end = "\ze [ '" ] "contained contains = shBracketExpr , shDerefSimple , shDeref , shEscape 392syn match shAstQuote contained '\*\ze" 'nextgroup = shString 393syn match shTestOpr contained '[ ^-+/% ] \zs= 'skipwhite nextgroup = shTestDoubleQuote , shTestSingleQuote , shTestPattern 394syn match shTestOpr contained "<=\|>=\|!=\|==\|=\~\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\| [ !<> ] " 395syn match shTestPattern contained '\w\+ ' 396syn region shTestDoubleQuote contained start = '\%(\%(\\\\\) * \\\)\@<!" 'skip = +\\\\\|\\" +end = '" 'contains = shDeref , shDerefSimple , shDerefSpecial 397syn match shTestSingleQuote contained '\\. 'nextgroup = shTestSingleQuote 398syn match shTestSingleQuote contained "' [ ^' ] * ' " 399if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 400syn region shDblBrace matchgroup = Delimiter start = "\[\[\s\@= "skip = +\%(\\\\\) * \\$ +end = "\]\] "contains = @shTestList , shAstQuote , shNoQuote , shComment 401syn region shDblParen matchgroup = Delimiter start = "(( "skip = +\%(\\\\\) * \\$ +end = ")) "contains = @shTestList , shComment 402endif 403 404" Character Class In Range: {{{1 405" ========================= 406syn match shCharClassOther contained "\[:\w\{-}:\] " 407syn match shCharClass contained "\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|xdigit\):\] " 408syn match shCollSymb contained "\[\..\{-}\.\] " 409syn match shEqClass contained "\[=.\{-}=\] " 410 411" Loops: do, if, while, until {{{1 412" ====== 413ShFoldIfDoFor syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList 414ShFoldIfDoFor syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList 415ShFoldIfDoFor syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn 416if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) 417ShFoldIfDoFor syn region shForPP matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=@shForList 418endif 419 420if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) || exists ( "b:is_posix" ) 421syn cluster shCaseList add = shRepeat 422syn cluster shFunctionList add = shRepeat 423syn region shRepeat matchgroup = shLoop start = "\<while\_s "end = "\<do\> "me= e-2contains = @shLoopList , shDblParen , shDblBrace 424syn region shRepeat matchgroup = shLoop start = "\<until\_s "end = "\<do\> "me= e-2contains = @shLoopList , shDblParen , shDblBrace 425if ! exists ( "b:is_posix" ) 426syn region shCaseEsac matchgroup = shConditional start = "\<select\s "matchgroup = shConditional end = "\<in\> "end = "\<do\> "contains = @shLoopList 427endif 428else 429syn region shRepeat matchgroup = shLoop start = "\<while\_s "end = "\<do\> "me= e-2contains = @shLoopList 430syn region shRepeat matchgroup = shLoop start = "\<until\_s "end = "\<do\> "me= e-2contains = @shLoopList 431endif 432syn region shCurlyIn contained matchgroup = Delimiter start = "{ "end = "} "contains = @shCurlyList 433syn match shComma contained ", " 434 435" Case: case...esac {{{1 436" ==== 437syn match shCaseBar contained skipwhite "\(^\| [ ^\\ ] \)\(\\\\\) * \zs| "nextgroup = shCase , shCaseStart , shCaseBar , shComment , shCaseExSingleQuote , shCaseSingleQuote , shCaseDoubleQuote 438syn match shCaseStart contained skipwhite skipnl "( "nextgroup = shCase , shCaseBar 439syn match shCaseLabel contained skipwhite "\%(\\.\| [ -a-zA-Z0-9_*. ] \)\+ "contains = shBracketExpr 440if exists ( "b:is_bash" ) || ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" ) && ! exists ( "b:is_ksh93u" ) && ! exists ( "b:is_ksh93v" ) && ! exists ( "b:is_ksh2020" )) 441ShFoldIfDoFor 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 442elseif exists ( "b:is_kornshell" ) 443ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end=";&" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment 444else 445ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment 446endif 447ShFoldIfDoFor syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList 448 449syn keyword shCaseIn contained skipwhite skipnl in nextgroup = shCase , shCaseStart , shCaseBar , shComment , shCaseExSingleQuote , shCaseSingleQuote , shCaseDoubleQuote 450if exists ( "b:is_bash" ) || ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" )) 451syn region shCaseExSingleQuote matchgroup = shQuote start = +\$' +skip = +\\\\\|\\. +end = +' +contains = shStringSpecial , shSpecial skipwhite skipnl nextgroup = shCaseBar contained 452else 453ShDefSynErrRule syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained 454endif 455syn region shCaseSingleQuote matchgroup = shQuote start = +' +end = +' +contains = shStringSpecial skipwhite skipnl nextgroup = shCaseBar contained 456syn region shCaseDoubleQuote matchgroup = shQuote start = +" +skip = +\\\\\|\\. +end = +" +contains = @shDblQuoteList , shStringSpecial skipwhite skipnl nextgroup = shCaseBar contained 457syn region shCaseCommandSub start = +` +skip = +\\\\\|\\. +end = +` +contains = @shCommandSubList skipwhite skipnl nextgroup = shCaseBar contained 458call s: GenerateBracketExpressionItems ({ 'itemGroup' : 'shCaseRange' , 'bracketGroup' : 'shBracketExprDelim' , 'extraArgs' : 'skip=+\\\\+ contained' }) 459if exists ( "b:is_bash" ) 460syn match shCharClass "\[:\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\] "contained 461elseif exists ( "b:is_kornshell" ) 462syn match shCharClass "\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\] "contained 463endif 464" Misc: {{{1 465"====== 466syn match shWrapLineOperator "\\$ " 467syn region shCommandSubBQ start = "` "skip = "\\\\\|\\. "end = "` "contains = shBQComment , @shCommandSubList 468syn 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! 476if exists ( "b:is_kornshell" ) || exists ( "b:is_bash" ) || exists ( "b:is_posix" ) 477syn region shCommandSub matchgroup = shCmdSubRegion start = "\$((\@! "skip = '\\\\\|\\. 'end = ") "contains = @shCommandSubList 478if exists ( "b:is_kornshell" ) 479if ! exists ( "b:is_ksh88" ) 480if exists ( "b:is_mksh" ) 481syn region shSubshare matchgroup = shCmdSubRegion start = "\${\ze [ \t\n ] "skip = '\\\\\|\\. 'end = "\zs [ \t\n; ] } "contains = @shCommandSubList 482else 483syn region shSubshare matchgroup = shCmdSubRegion start = "\${\ze [ \t\n< ] "skip = '\\\\\|\\. 'end = "\zs [ \t\n; ] } "contains = @shCommandSubList 484endif 485endif 486if exists ( "b:is_mksh" ) || exists ( "b:generic_korn" ) 487syn region shValsub matchgroup = shCmdSubRegion start = "\${| "skip = '\\\\\|\\. 'end = "} "contains = @shCommandSubList 488endif 489elseif exists ( "b:is_bash" ) 490syn region shSubshare matchgroup = shCmdSubRegion start = "\${\ze [ \t\n ] "skip = '\\\\\|\\. 'end = "\zs [ ;\n ][ \t\n ] * } "contains = @shCommandSubList 491syn region shValsub matchgroup = shCmdSubRegion start = "\${| "skip = '\\\\\|\\. 'end = "[ ;\n ][ \t\n ] * } "contains = @shCommandSubList 492endif 493syn region shArithmetic matchgroup = shArithRegion start = "\$(( "skip = '\\\\\|\\. 'end = ")) "contains = @shArithList 494syn region shArithmetic matchgroup = shArithRegion start = "\$\[ "skip = '\\\\\|\\. 'end = "\] "contains = @shArithList 495syn match shSkipInitWS contained "^\s\+ " 496syn region shArithParen matchgroup = shArithRegion contained start = "( "end = ") "contains = @shArithParenList 497else 498ShDefSynErrRule syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList 499endif 500syn region shCmdParenRegion matchgroup = shCmdSubRegion start = "((\@! "skip = '\\\\\|\\. 'end = ") "contains = @shCommandSubList 501 502if exists ( "b:is_bash" ) 503syn cluster shCommandSubList add = bashSpecialVariables , bashStatement 504syn cluster shCaseList add = bashAdminStatement , bashStatement 505syn 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 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 506syn 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 507syn keyword bashStatement typeset nextgroup = shSetOption 508syn keyword bashAdminStatement reload restart start status stop 509endif 510 511" for all kornshells 512if exists ( "b:is_kornshell" ) 513syn cluster shCaseList add = kshStatement 514syn cluster shCommandSubList add = kshSpecialVariables , kshStatement 515syn 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 MAILCHECK MAILPATH OLDPWD OPTARG OPTIND PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELL SHLVL TMOUT VISUAL 516syn keyword kshStatement autoload builtin compound disown enum fg float functions hist history integer let nameref r redirect source stop suspend time whence 517syn keyword shStatement typeset skipwhite nextgroup = shSetOption 518endif 519 520" kornshell flavors 521if exists ( "b:generic_korn" ) 522syn 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 523syn keyword kshStatement alarm bind compgen complete eloop fds mkservice pids poll sha2sum vmstate xgrep 524elseif exists ( "b:is_ksh88" ) 525syn keyword kshSpecialVariables contained ERRNO 526elseif exists ( "b:is_ksh93" ) 527syn 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 528syn keyword kshStatement alarm compgen complete eloop fds mkservice pids poll sha2sum vmstate xgrep 529elseif exists ( "b:is_ksh93v" ) 530syn 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 531syn keyword kshStatement alarm compgen complete fds pids poll sha2sum vmstate xgrep 532elseif exists ( "b:is_ksh93u" ) 533syn 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 534syn keyword kshStatement alarm fds pids vmstate 535elseif exists ( "b:is_ksh2020" ) 536syn 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 537syn keyword kshStatement compgen complete 538elseif exists ( "b:is_mksh" ) 539syn keyword kshSpecialVariables contained BASHPID EPOCHREALTIME EXECSHELL KSHEGID KSHGID KSHUID KSH_MATCH PATHSEP PGRP PIPESTATUS TMPDIR USER_ID 540syn keyword kshStatement bind 541endif 542 543syn match shSource "^\.\s " 544syn match shSource "\s\.\s " 545if exists ( "b:is_kornshell" ) || exists ( "b:is_posix" ) 546syn match shColon '^\s * \zs: ' 547endif 548 549" String And Character Constants: {{{1 550"================================ 551syn match shNumber "\<\d\+\>#\= " 552syn match shNumber "\<-\=\.\=\d\+\>#\= " 553syn match shCtrlSeq "\\\d\d\d\|\\ [ abcfnrtv0 ] "contained 554if exists ( "b:is_bash" ) || exists ( "b:is_kornshell" ) 555syn match shSpecial "[ ^\\ ] \(\\\\\) * \zs\\\o\o\o\|\\x\x\x\|\\c [ ^" ] \|\\ [ abefnrtv ] "contained 556syn match shSpecial "^\(\\\\\) * \zs\\\o\o\o\|\\x\x\x\|\\c [ ^" ] \|\\ [ abefnrtv ] "contained 557syn region shExSingleQuote matchgroup = shQuote start = +\$' +skip = +\\\\\|\\. +end = +' +contains = shStringSpecial , shSpecial nextgroup = shSpecialNxt 558syn region shExDoubleQuote matchgroup = shQuote start = +\$" +skip = +\\\\\|\\.\|\\" +end = +" +contains = @shDblQuoteList , shStringSpecial , shSpecial nextgroup = shSpecialNxt 559else 560ShDefSynErrRule syn region shExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial 561ShDefSynErrRule syn region shExDoubleQuote matchgroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial 562endif 563syn region shSingleQuote matchgroup = shQuote start = +' +end = +' +contains = @Spell nextgroup = shSpecialStart , shSpecialSQ 564syn region shDoubleQuote matchgroup = shQuote start = +\%(\%(\\\\\) * \\\)\@<!" +skip = +\\. +end = +" +contains = @shDblQuoteList , shStringSpecial , @Spell nextgroup = shSpecialStart 565syn match shStringSpecial "[ ^[:print: ] \t] "contained 566syn match shStringSpecial "[ ^\\ ] \zs\%(\\\\\) * \(\\ [ \\"'`$()# ] \)\+ "nextgroup = shComment 567syn match shSpecialSQ "[ ^\\ ] \zs\%(\\\\\) * \(\\ [ \\"'`$()# ] \)\+ "contained nextgroup = shBkslshSnglQuote , @shNoZSList 568syn match shSpecialDQ "[ ^\\ ] \zs\%(\\\\\) * \(\\ [ \\"'`$()# ] \)\+ "contained nextgroup = shBkslshDblQuote , @shNoZSList 569syn match shSpecialStart "\%(\\\\\) * \\ [ \\"'`$()# ] "contained nextgroup = shBkslshSnglQuote , shBkslshDblQuote , @shNoZSList 570syn match shSpecial "^\%(\\\\\) * \\ [ \\"'`$()# ] " 571syn match shSpecialNoZS contained "\%(\\\\\) * \\ [ \\"'`$()# ] " 572syn match shSpecialNxt contained "\\ [ \\"'`$()# ] " 573 574" Comments: {{{1 575"========== 576syn cluster shCommentGroup contains = shTodo , @Spell 577if exists ( "b:is_bash" ) 578syn match shTodo contained "\<\%(COMBAK\|FIXME\|TODO\|XXX\)\ze:\=\> " 579else 580syn keyword shTodo contained COMBAK FIXME TODO XXX 581endif 582syn match shComment "^\s * \zs#. * $ "contains = @shCommentGroup 583syn match shComment "\s\zs#. * $ "contains = @shCommentGroup 584syn match shComment contained "#. * $ "contains = @shCommentGroup 585syn match shQuickComment contained "#. * $ "contains = @shCommentGroup 586syn match shBQComment contained "#.\{-}\ze` "contains = @shCommentGroup 587 588" Here Documents: {{{1 589" (modified by Felipe Contreras) 590" ========================================= 591ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc01 start="<<\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc01 end="^\z1$" contains=@shDblQuoteList 592ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc02 start="<<-\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc02 end="^\t*\z1$" contains=@shDblQuoteList 593ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc03 start="<<\s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc03 end="^\z1$" 594ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc04 start="<<-\s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc04 end="^\t*\z1$" 595ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc05 start="<<\s*'\z([^']\+\)'" matchgroup=shHereDoc05 end="^\z1$" 596ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc06 start="<<-\s*'\z([^']\+\)'" matchgroup=shHereDoc06 end="^\t*\z1$" 597ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc07 start="<<\s*\"\z([^"]\+\)\"" matchgroup=shHereDoc07 end="^\z1$" 598ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc08 start="<<-\s*\"\z([^"]\+\)\"" matchgroup=shHereDoc08 end="^\t*\z1$" 599ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc09 start="<<\s*\\\_$\_s*\z([^ \t|>]\+\)" matchgroup=shHereDoc09 end="^\z1$" contains=@shDblQuoteList 600ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc10 start="<<-\s*\\\_$\_s*\z([^ \t|>]\+\)" matchgroup=shHereDoc10 end="^\t*\z1$" contains=@shDblQuoteList 601ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc11 start="<<\s*\\\_$\_s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc11 end="^\z1$" 602ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc12 start="<<-\s*\\\_$\_s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc12 end="^\t*\z1$" 603ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc13 start="<<\s*\\\_$\_s*'\z([^']\+\)'" matchgroup=shHereDoc13 end="^\z1$" 604ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc14 start="<<-\s*\\\_$\_s*'\z([^']\+\)'" matchgroup=shHereDoc14 end="^\t*\z1$" 605ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc15 start="<<\s*\\\_$\_s*\"\z([^"]\+\)\"" matchgroup=shHereDoc15 end="^\z1$" 606ShFoldHereDoc 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 612if exists ( "b:is_bash" ) || (( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" )) && ! exists ( "b:is_posix" )) 613syn match shHereString "<<< "skipwhite nextgroup = shCmdParenRegion 614endif 615 616" Identifiers: {{{1 617"============= 618syn match shSetOption "\s\zs [ -+ ][ a-zA-Z0-9 ] \+\> "contained 619syn match shVariable "\<\h\w * \ze= "nextgroup = shVarAssign 620if exists ( "b:is_bash" ) 621" The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". 622syn region shArrayValue contained start = "\[\%(..\{-}\]=\)\@= "end = "\]=\@= "contains = @shArrayValueList nextgroup = shVarAssign 623syn cluster shArrayValueList contains = shArithmetic , shArithParen , shCommandSub , shDeref , shDerefSimple , shEscape , shExpr , shNumber , shExSingleQuote , shExDoubleQuote , shSingleQuote , shDoubleQuote , shSpecial , shParen , bashSpecialVariables , shParenError 624syn region shArrayRegion contained matchgroup = shShellVariables start = "( "skip = '\\\\\|\\. 'end = ") "contains = @shArrayValueList , shArrayValue , shComment 625elseif ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" )) 626" The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". 627syn region shArrayValue contained start = "\[\%(..\{-}\]=\)\@= "end = "\]=\@= "contains = @shArrayValueList nextgroup = shVarAssign 628syn cluster shArrayValueList contains = shArithmetic , shArithParen , shCommandSub , shDeref , shDerefSimple , shEscape , shExpr , shNumber , shExSingleQuote , shExDoubleQuote , shSingleQuote , shDoubleQuote , shSpecial , shParen , kshSpecialVariables , shParenError 629syn region shArrayRegion contained matchgroup = shShellVariables start = "( "skip = '\\\\\|\\. 'end = ") "contains = @shArrayValueList , shArrayValue , shComment , shArrayRegion 630endif 631if exists ( "b:is_bash" ) || exists ( "b:is_kornshell" ) 632syn match shVariable "\<\h\w * \%(\[..\{-}\]\)\=\ze\%( [ |^&*/%+- ] \| [ <^ ] <\| [ >^ ] >\)\== "contains = shDerefVarArray nextgroup = shVarAssign 633syn match shVarAssign contained "\%( [ |^&*/%+- ] \| [ <^ ] <\| [ >^ ] >\)\== "nextgroup = shArrayRegion , shPattern , shDeref , shDerefSimple , shDoubleQuote , shExDoubleQuote , shSingleQuote , shExSingleQuote , shVar 634else 635syn match shVarAssign contained "= "nextgroup = shPattern , shDeref , shDerefSimple , shDoubleQuote , shExDoubleQuote , shSingleQuote , shExSingleQuote , shVar 636endif 637syn match shVar contained "\h\w * " 638syn region shAtExpr contained start = "@( "end = ") "contains = @shIdList 639if exists ( "b:is_bash" ) 640syn match shSet "^\s * set\ze\s\+$ " 641syn 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 642syn 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 643elseif exists ( "b:is_kornshell" ) || exists ( "b:is_posix" ) 644syn match shSet "^\s * set\ze\s\+$ " 645if exists ( "b:is_dash" ) 646syn region shSetList oneline matchgroup = shSet start = "\<\%(local\)\>\ze [ / ] \@! "end = "$ "matchgroup = shSetListDelim end = "\ze [ }|);& ] "matchgroup = NONE end = "\ze\s\+ [ #= ] "contains = @shIdList 647syn keyword shStatement chdir 648endif 649syn region shSetList oneline matchgroup = shSet start = "\<\(export\)\>\ze [ / ] \@! "end = "$ "matchgroup = shSetListDelim end = "\ze [ }|);& ] "matchgroup = NONE end = "\ze\s\+ [ #= ] "contains = @shIdList 650syn 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 651else 652syn 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 653endif 654 655" KornShell namespace: {{{1 656if exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" ) && ! exists ( "b:is_mksh" ) 657syn keyword shFunctionKey namespace skipwhite nextgroup = shNamespaceOne 658endif 659 660" Functions: {{{1 661if ! exists ( "b:is_posix" ) 662syn match shFunctionKeyDelim "\s\+ "contained transparent nextgroup = shDoError , shIfError , shFunctionNameCommentError , shFunctionTwo , shFunctionFour , shFunctionCmdTwo 663syn match shFunctionKey "\<function\s\@= "nextgroup = shFunctionKeyDelim 664endif 665 666ShFoldFunctions syn region shFunctionExpr matchgroup=shFunctionExprRegion start="{" end="}" contains=@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment 667ShFoldFunctions syn region shFunctionSubSh matchgroup=shFunctionSubShRegion start="(" end=")" contains=@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment 668 669syn match shFunctionParens "() "contained 670 671if exists ( "b:is_bash" ) 672syn keyword shFunctionKey coproc 673syn match shFunctionCmdOne "\%#=1^\s * \zs\%(\%(\<\k\+\| [ ^()<>|&$;\t ] \+\)\+\)\@>\s * ()\ze\_s * \%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\) "skipwhite skipnl nextgroup = @shFunctionCmds contains = shFunctionParens 674syn match shFunctionCmdTwo "\%#=1\%(\%(\<\k\+\>\| [ ^()<>|&$;\t ] \+\)\+\)\@>\ze\s * \%(()\ze\)\=\_s * \%(\<\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\) "contained skipwhite skipnl nextgroup = @shFunctionCmds contains = shFunctionParens 675syn match shFunctionOne "\%#=1^\s * \zs\%(\%(\<\k\+\| [ ^()<>|&$;\t ] \+\)\+\)\@>\s * ()\ze\_s * { "skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 676syn 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:]]()"). 681syn match shFunctionFour "\%#=1\%(\%(\<\k\+\| [ ^()<>|&$;\t ] \+\)\+\)\@>\ze\%(\%(\s * ()\ze\)\=\)\@>\_s * ((\@! "contained skipwhite skipnl nextgroup = shFunctionSubSh contains = shFunctionParens 682syn match shFunctionTwo "\%#=1\%(\%(\<\k\+\| [ ^()<>|&$;\t ] \+\)\+\)\@>\ze\%(\%(\s * ()\ze\)\=\)\@>\_s * { "contained skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 683" Claim empty array assignments. 684syn match shArrayEmptyDecl "\%#=1\ze\%(\<\h\w * =\)\@>() "transparent nextgroup = shVariable 685" Claim commented out function declaration headers. 686syn match shFunctionComment "^\s * \zs\ze# "transparent nextgroup = shComment 687ShDefSynErrRule syn match shFunctionNameAssignError"\%#=1\%(\%(\<\h\w*\)\@>=\)\%(\%(\w\+\)\@>=\=\)\+()" skipwhite skipnl nextgroup=shExpr,shSubSh 688ShDefSynErrRule syn match shFunctionNameCommentError"#" contained 689elseif exists ( "b:is_ksh88" ) 690" AT&T ksh88 691syn match shFunctionCmdOne "^\s * \zs\h\w * \s * ()\ze\_s * \%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\) "skipwhite skipnl nextgroup = @shFunctionCmds contains = shFunctionParens 692syn match shFunctionOne "^\s * \zs\h\w * \s * ()\ze\_s * { "skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 693syn match shFunctionTwo "\<\h\w * \>\ze\_s * { "contained skipwhite skipnl nextgroup = shFunctionExpr 694syn match shFunctionThree "^\s * \zs\h\w * \s * ()\ze\_s * ((\@! "skipwhite skipnl nextgroup = shFunctionSubSh contains = shFunctionParens 695elseif exists ( "b:is_mksh" ) 696" MirBSD ksh is the wild west of absurd and abstruse function names... 697syn 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 698syn match shFunctionOne "^\s * \zs [ -A-Za-z_@!+.%,0-9: ] * [ -A-Za-z_.%,0-9: ] \s * ()\ze\_s * { "skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 699syn match shFunctionTwo "\%#=1\%(\%(\<\w\+\| [ @!+.%,:- ] \+\) * [ -A-Za-z_.%,0-9: ] \)\@>\ze\s * \%(()\ze\)\=\_s * { "contained skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 700syn match shFunctionThree "^\s * \zs [ -A-Za-z_@!+.%,0-9: ] * [ -A-Za-z_.%,0-9: ] \s * ()\ze\_s * ((\@! "skipwhite skipnl nextgroup = shFunctionSubSh contains = shFunctionParens 701elseif exists ( "b:is_kornshell" ) 702" ksh93 703syn 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 704syn match shFunctionOne "^\s * \zs [ A-Za-z_. ][ A-Za-z_.0-9 ] * \s * ()\ze\_s * { "skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 705syn match shFunctionTwo "\%(\<\h\+\|\.\) [ A-Za-z_.0-9 ] * \ze\_s * { "contained skipwhite skipnl nextgroup = shFunctionExpr 706syn match shFunctionThree "^\s * \zs [ A-Za-z_. ][ A-Za-z_.0-9 ] * \s * ()\ze\_s * ((\@! "skipwhite skipnl nextgroup = shFunctionSubSh contains = shFunctionParens 707syn match shNamespaceOne "\<\h\w * \>\ze\_s * { "contained skipwhite skipnl nextgroup = shFunctionExpr 708else 709syn match shFunctionCmdOne "^\s * \zs\h\w * \s * ()\ze\_s * \%(for\|case\|if\|while\|until\)\> "skipwhite skipnl nextgroup = @shFunctionCmds contains = shFunctionParens 710syn match shFunctionCmdTwo "\<\h\w * \s * ()\ze\_s * \%(for\|case\|if\|while\|until\)\> "contained skipwhite skipnl nextgroup = @shFunctionCmds contains = shFunctionParens 711syn match shFunctionOne "^\s * \zs\h\w * \s * ()\ze\_s * { "skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 712syn match shFunctionTwo "\<\h\w * \>\s * ()\ze\_s * { "contained skipwhite skipnl nextgroup = shFunctionExpr contains = shFunctionParens 713syn match shFunctionThree "^\s * \zs\h\w * \s * ()\ze\_s * ( "skipwhite skipnl nextgroup = shFunctionSubSh contains = shFunctionParens 714syn match shFunctionFour "\<\h\w * \>\s * ()\ze\_s * ( "contained skipwhite skipnl nextgroup = shFunctionSubSh contains = shFunctionParens 715endif 716 717ShDefSynErrRule syn match shDoError"\<do\%(ne\)\=\s*()" 718ShDefSynErrRule syn match shIfError"\<then\s*()" 719ShDefSynErrRule syn match shIfError"\<else\s*()" 720 721" Parameter Dereferencing: {{{1 722" ======================== 723ShDefSynErrRule syn match shDerefWordError"[^}$[~]" contained 724syn match shDerefSimple "\$\%(\h\w * \|\d\) "nextgroup = @shNoZSList 725if exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" ) 726if exists ( "b:is_mksh" ) 727syn region shDeref matchgroup = PreProc start = "\${\ze [ ^ \t\n| ] "end = "} "contains = @shDerefList , shDerefVarArray nextgroup = shSpecialStart 728elseif exists ( "b:generic_korn" ) 729syn region shDeref matchgroup = PreProc start = "\${\ze [ ^ \t\n<| ] "end = "} "contains = @shDerefList , shDerefVarArray nextgroup = shSpecialStart 730else 731syn region shDeref matchgroup = PreProc start = "\${\ze [ ^ \t\n< ] "end = "} "contains = @shDerefList , shDerefVarArray nextgroup = shSpecialStart 732endif 733elseif exists ( "b:is_bash" ) 734syn region shDeref matchgroup = PreProc start = "\${\ze [ ^ \t\n| ] "end = "} "contains = @shDerefList , shDerefVarArray nextgroup = shSpecialStart 735else 736syn region shDeref matchgroup = PreProc start = "\${ "end = "} "contains = @shDerefList , shDerefVarArray nextgroup = shSpecialStart 737endif 738syn match shDerefSimple "\$ [ -#*@!? ] "nextgroup = @shNoZSList 739syn match shDerefSimple "\$\$ "nextgroup = @shNoZSList 740syn match shDerefSimple "\${\d} "nextgroup = @shNoZSList nextgroup = shSpecialStart 741if exists ( "b:is_bash" ) || exists ( "b:is_kornshell" ) || exists ( "b:is_posix" ) 742syn region shDeref matchgroup = PreProc start = "\${##\= "end = "} "contains = @shDerefList nextgroup = @shSpecialNoZS , shSpecialStart 743syn region shDeref matchgroup = PreProc start = "\${\$\$ "end = "} "contains = @shDerefList nextgroup = @shSpecialNoZS , shSpecialStart 744endif 745 746" ksh: ${.sh.*} variables: {{{1 747" ======================================== 748if exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" ) && ! exists ( "b:is_mksh" ) 749syn match shDerefVar contained "\.\+ "nextgroup = @shDerefVarList 750syn region shDeref matchgroup = PreProc start = "\${\ze [ \. ] "end = "} "contains = @shDerefVarList , shDerefPSR , shDerefPPS 751endif 752 753" ksh: ${!var[*]} array index list syntax: {{{1 754" ======================================== 755if ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" )) || exists ( "b:is_posix" ) 756syn region shDeref matchgroup = PreProc start = "\${! "end = "} "contains = @shDerefVarArray 757endif 758 759" bash: ${!prefix*} and ${#parameter}: {{{1 760" ==================================== 761if exists ( "b:is_bash" ) 762syn region shDeref matchgroup = PreProc start = "\${! "end = "\*\=} "contains = @shDerefList , shDerefOffset 763syn match shDerefVar contained "{\@<=!\h\w * "nextgroup = @shDerefVarList 764syn match shDerefSpecial contained "\({!\)\@<= [ [:alnum: ] * #@_]\+ "nextgroup = @shDerefVarList , shDerefOp 765endif 766if ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" )) 767syn match shDerefVar contained "{\@<=!\h\w * [ [:alnum: ] _.] * "nextgroup = @shDerefVarList 768syn match shDerefSpecial contained "\({!\)\@<= [ [:alnum: ] * #@_]\+ "nextgroup = @shDerefVarList , shDerefOp 769endif 770 771syn match shDerefSpecial contained "{\@<= [ -*@?0 ] "nextgroup = shDerefOp , shDerefOffset , shDerefOpError 772syn match shDerefSpecial contained "\({ [ # ] \)\@<= [ [:alnum: ] * @_]\+ "nextgroup = @shDerefVarList , shDerefOp 773syn match shDerefVar contained "{\@<=\h\w * "nextgroup = @shDerefVarList 774syn match shDerefVar contained '\d 'nextgroup = @shDerefVarList 775if exists ( "b:is_kornshell" ) || exists ( "b:is_posix" ) 776syn match shDerefVar contained "{\@<=\h\w * [ [:alnum: ] _.] * "nextgroup = @shDerefVarList 777endif 778 779" sh ksh bash : ${var[... ]...} array reference: {{{1 780syn 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]) 797syn cluster shDerefPatternList contains = shDerefPattern , shDerefString 798ShDefSynErrRule syn match shDerefOpError contained":[[:punct:]]" 799syn match shDerefOp contained ":\= [ -=? ] "nextgroup = @shDerefPatternList 800syn match shDerefOp contained ":\=+ "nextgroup = @shDerefPatternList 801if exists ( "b:is_bash" ) || exists ( "b:is_kornshell" ) || exists ( "b:is_posix" ) 802syn match shDerefOp contained "#\{1,2} "nextgroup = @shDerefPatternList 803syn match shDerefOp contained "%\{1,2} "nextgroup = @shDerefPatternList 804syn match shDerefPattern contained "[ ^{} ] \+ "contains = shDeref , shDerefSimple , shDerefPattern , shDerefString , shCommandSub , shDerefEscape nextgroup = shDerefPattern skipnl 805syn region shDerefPattern contained start = "{ "end = "} "contains = shDeref , shDerefSimple , shDerefString , shCommandSub nextgroup = shDerefPattern 806" Match parametric bracket expressions with a leading whitespace character. 807syn region shDerefPattern contained matchgroup = shBracketExprDelim start = "\[ "end = "\] "contains = @shBracketExprList , shDoubleQuote nextgroup = shDerefPattern 808call s: GenerateBracketExpressionItems ({ 'itemGroup' : 'shDerefPattern' , 'bracketGroup' : 'shBracketExprDelim' , 'extraArgs' : 'contained nextgroup=shDerefPattern' }) 809syn match shDerefEscape contained '\%(\\\\\) * \\. ' 810endif 811if exists ( "b:is_bash" ) || ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" ) && ! exists ( "b:is_mksh" ) && ! exists ( "b:is_ksh93u" ) && ! exists ( "b:is_ksh2020" )) 812syn match shDerefOp contained "[ ,^ ] \{1,2} "nextgroup = @shDerefPatternList 813endif 814if exists ( "b:is_bash" ) 815syn match shDerefOp contained "@ [ uULQEPAKa ] " 816endif 817syn region shDerefString contained matchgroup = shDerefDelim start = +\%(\\\)\@<!' +end = +' + 818syn region shDerefString contained matchgroup = shDerefDelim start = +\%(\\\)\@<!" +skip = +\\" +end = +" +contains = @shDblQuoteList , shStringSpecial 819syn match shDerefString contained "\\ [ "' ] "nextgroup = shDerefPattern 820 821if 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} 824syn region shDerefOffset contained start = ': [ ^-=?+ ] 'end = '\ze: 'end = '\ze} 'contains = shDeref , shDerefSimple , shDerefEscape nextgroup = shDerefLen , shDeref , shDerefSimple 825syn region shDerefOffset contained start = ':\s- 'end = '\ze: 'end = '\ze} 'contains = shDeref , shDerefSimple , shDerefEscape nextgroup = shDerefLen , shDeref , shDerefSimple 826syn match shDerefLen contained ": [ ^} ] \+ "contains = shDeref , shDerefSimple , shArithmetic 827endif 828 829if exists ( "b:is_bash" ) || ( exists ( "b:is_kornshell" ) && ! exists ( "b:is_ksh88" )) 830" bash ksh : ${parameter/pattern/string} 831" bash ksh : ${parameter//pattern/string} 832syn match shDerefPPS contained '/\{1,2} 'nextgroup = shDerefPPSleft 833syn region shDerefPPSleft contained start = '. 'skip = @\%(\\\\\) * \\/ @matchgroup = shDerefOp end = '/ 'end = '\ze} 'end = '" 'nextgroup = shDerefPPSright contains = @shPPSLeftList 834syn region shDerefPPSright contained start = '. 'skip = @\%(\\\\\)\+ @end = '\ze} 'contains = @shPPSRightList 835 836" bash ksh : ${parameter/#pattern/string} 837" bash ksh : ${parameter/%pattern/string} 838syn match shDerefPSR contained '/ [ #% ] 'nextgroup = shDerefPSRleft , shDoubleQuote , shSingleQuote 839syn region shDerefPSRleft contained start = '[ ^"' ] 'skip = @\%(\\\\\) * \\/ @matchgroup = shDerefOp end = '/ 'end = '\ze} 'nextgroup = shDerefPSRright contains = shBracketExpr 840syn region shDerefPSRright contained start = '. 'skip = @\%(\\\\\)\+ @end = '\ze} ' 841endif 842 843" Arithmetic Parenthesized Expressions: {{{1 844"syn region shParen matchgroup=shArithRegion start='[^$]\zs(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList 845syn region shParen matchgroup = shArithRegion start = '\$\@!(\%(\ze [ ^( ] \|$\) 'end = ') 'contains = @shArithParenList 846 847" Additional sh Keywords: {{{1 848" =================== 849" builtins: 850syn 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: 852syn 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 853syn keyword shConditional contained elif else then 854ShDefSynErrRule syn keyword shCondError elif else then 855 856" Synchronization: {{{1 857" ================ 858if ! exists ( "g:sh_minlines" ) 859let s: sh_minlines = 200 860else 861let s: sh_minlines = g: sh_minlines 862endif 863if ! exists ( "g:sh_maxlines" ) 864let s: sh_maxlines = 2 * s: sh_minlines 865if s: sh_maxlines < 25 866let s: sh_maxlines = 25 867endif 868else 869let s: sh_maxlines = g: sh_maxlines 870endif 871exec "syn sync minlines=" . s: sh_minlines . " maxlines=" . s: sh_maxlines 872syn syncmatch shCaseEsacSync grouphereshCaseEsac "\<case\> " 873syn syncmatch shCaseEsacSync groupthereshCaseEsac "\<esac\> " 874syn syncmatch shDoSync grouphereshDo "\<do\> " 875syn syncmatch shDoSync groupthereshDo "\<done\> " 876syn syncmatch shForSync grouphereshFor "\<for\> " 877syn syncmatch shForSync groupthereshFor "\<in\> " 878syn syncmatch shIfSync grouphereshIf "\<if\> " 879syn syncmatch shIfSync groupthereshIf "\<fi\> " 880syn syncmatch shUntilSync grouphereshRepeat "\<until\> " 881syn syncmatch shWhileSync grouphereshRepeat "\<while\> " 882 883" Default Highlighting: {{{1 884" ===================== 885if ! exists ( "skip_sh_syntax_inits" ) 886hi def link shArithRegion shShellVariables 887hi def link shArrayValue shDeref 888hi def link shAstQuote shDoubleQuote 889hi def link shAtExpr shSetList 890hi def link shBkslshSnglQuote shSingleQuote 891hi def link shBkslshDblQuote shDOubleQuote 892hi def link shBeginHere shRedir 893hi def link shCaseBar shConditional 894hi def link shCaseCommandSub shCommandSub 895hi def link shCaseDoubleQuote shDoubleQuote 896hi def link shCaseIn shConditional 897hi def link shQuote shOperator 898hi def link shCaseSingleQuote shSingleQuote 899hi def link shCaseStart shConditional 900hi def link shCmdSubRegion shShellVariables 901hi def link shColon shComment 902hi def link shDerefOp shOperator 903hi def link shDerefPOL shDerefOp 904hi def link shDerefPPS shDerefOp 905hi def link shDerefPSR shDerefOp 906hi def link shDeref shShellVariables 907hi def link shDerefDelim shOperator 908hi def link shDerefSimple shDeref 909hi def link shDerefSpecial shDeref 910hi def link shDerefString shDoubleQuote 911hi def link shDerefVar shDeref 912hi def link shDoubleQuote shString 913hi def link shEcho shString 914hi def link shEchoDelim shOperator 915hi def link shEchoQuote shString 916hi def link shForPP shLoop 917hi def link shEmbeddedEcho shString 918hi def link shEscape shCommandSub 919hi def link shExDoubleQuote shDoubleQuote 920hi def link shExSingleQuote shSingleQuote 921hi def link shHereDoc shString 922hi def link shHereString shRedir 923hi def link shHerePayload shHereDoc 924hi def link shLoop shStatement 925hi def link shSpecialNxt shSpecial 926hi def link shNoQuote shDoubleQuote 927hi def link shOption shCommandSub 928hi def link shPattern shString 929hi def link shParen shArithmetic 930hi def link shPosnParm shShellVariables 931hi def link shQuickComment shComment 932hi def link shBQComment shComment 933hi def link shRange shOperator 934hi def link shRedir shOperator 935hi def link shSetListDelim shOperator 936hi def link shSetOption shOption 937hi def link shSingleQuote shString 938hi def link shSource shOperator 939hi def link shStringSpecial shSpecial 940hi def link shSpecialStart shSpecial 941hi def link shSubShRegion shOperator 942hi def link shTestOpr shConditional 943hi def link shTestPattern shString 944hi def link shTestDoubleQuote shString 945hi def link shTestSingleQuote shString 946hi def link shTouchCmd shStatement 947hi def link shVariable shSetList 948hi def link shWrapLineOperator shOperator 949 950if exists ( "b:is_bash" ) 951hi def link bashAdminStatement shStatement 952hi def link bashSpecialVariables shShellVariables 953hi def link bashStatement shStatement 954hi def link shCharClass shSpecial 955hi def link shDerefOffset shDerefOp 956hi def link shDerefLen shDerefOffset 957endif 958if exists ( "b:is_kornshell" ) || exists ( "b:is_posix" ) 959hi def link kshSpecialVariables shShellVariables 960hi def link kshStatement shStatement 961endif 962 963ShLinkSynErrGroup hi def link shCaseError Error 964ShLinkSynErrGroup hi def link shCondError Error 965ShLinkSynErrGroup hi def link shCurlyError Error 966ShLinkSynErrGroup hi def link shDerefOpError Error 967ShLinkSynErrGroup hi def link shDerefWordError Error 968ShLinkSynErrGroup hi def link shDoError Error 969ShLinkSynErrGroup hi def link shEsacError Error 970ShLinkSynErrGroup hi def link shIfError Error 971ShLinkSynErrGroup hi def link shInError Error 972ShLinkSynErrGroup hi def link shParenError Error 973ShLinkSynErrGroup hi def link shTestError Error 974if exists ( "b:is_bash" ) 975ShLinkSynErrGroup hi def link shFunctionNameAssignError Error 976ShLinkSynErrGroup hi def link shFunctionNameCommentError Error 977endif 978if exists ( "b:is_kornshell" ) || exists ( "b:is_posix" ) 979ShLinkSynErrGroup hi def link shDTestError Error 980endif 981 982hi def link shArithmetic Special 983hi def link shBracketExprDelim Delimiter 984hi def link shCharClass Identifier 985hi def link shCollSymb shCharClass 986hi def link shEqClass shCharClass 987hi def link shSnglCase Statement 988hi def link shCommandSub Special 989hi def link shCommandSubBQ shCommandSub 990hi def link shSubshare shCommandSub 991hi def link shValsub shCommandSub 992hi def link shComment Comment 993hi def link shConditional Conditional 994hi def link shCtrlSeq Special 995hi def link shExprRegion Delimiter 996hi def link shFunctionKey Keyword 997hi def link shFunctionParens Delimiter 998hi def link shFunctionOne Function 999hi def link shFunctionTwo shFunctionOne 1000hi def link shFunctionThree shFunctionOne 1001hi def link shFunctionFour shFunctionOne 1002hi def link shFunctionCmdOne shFunctionOne 1003hi def link shFunctionCmdTwo shFunctionOne 1004hi def link shFunctionExprRegion shExprRegion 1005hi def link shFunctionSubShRegion shSubShRegion 1006hi def link shNamespaceOne Function 1007hi def link shNumber Number 1008hi def link shOperator Operator 1009hi def link shRepeat Repeat 1010hi def link shSet Statement 1011hi def link shSetList Identifier 1012hi def link shShellVariables PreProc 1013hi def link shSpecial Special 1014hi def link shSpecialDQ Special 1015hi def link shSpecialSQ Special 1016hi def link shSpecialNoZS shSpecial 1017hi def link shStatement Statement 1018hi def link shString String 1019hi def link shTodo Todo 1020hi def link shAlias Identifier 1021hi def link shHereDoc01 shRedir 1022hi def link shHereDoc02 shRedir 1023hi def link shHereDoc03 shRedir 1024hi def link shHereDoc04 shRedir 1025hi def link shHereDoc05 shRedir 1026hi def link shHereDoc06 shRedir 1027hi def link shHereDoc07 shRedir 1028hi def link shHereDoc08 shRedir 1029hi def link shHereDoc09 shRedir 1030hi def link shHereDoc10 shRedir 1031hi def link shHereDoc11 shRedir 1032hi def link shHereDoc12 shRedir 1033hi def link shHereDoc13 shRedir 1034hi def link shHereDoc14 shRedir 1035hi def link shHereDoc15 shRedir 1036hi def link shHereDoc16 shRedir 1037endif 1038 1039" Delete shell commands {{{1 1040" ===================== 1041delc ShFoldFunctions 1042delc ShFoldHereDoc 1043delc ShFoldIfDoFor 1044delc ShLinkSynErrGroup 1045delc ShDefSynErrRule 1046 1047" Delete shell functions {{{1 1048" ====================== 1049delfun s:ScanAndCondExecSynErrCmd 1050delfun s:GenerateBracketExpressionItems 1051 1052" Set Current Syntax: {{{1 1053" =================== 1054if exists ( "b:is_bash" ) 1055let b: current_syntax = "bash" 1056elseif exists ( "b:is_kornshell" ) 1057let b: current_syntax = "ksh" 1058elseif exists ( "b:is_posix" ) 1059let b: current_syntax = "posix" 1060else 1061let b: current_syntax = "sh" 1062endif 1063 1064" vim: ts=16 fdm=marker