Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: shell (sh) Korn shell (ksh) bash (sh) |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 3 | " Maintainer: Charles E. Campbell <NdrOchipS@PcampbellAfamily.Mbiz> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4 | " Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int> |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 5 | " Last Change: May 29, 2015 |
| 6 | " Version: 137 |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 7 | " URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH |
| 8 | " For options and settings, please use: :help ft-sh-syntax |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 9 | " This file includes many ideas from ?ric Brunet (eric.brunet@ens.fr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 11 | " For version 5.x: Clear all syntax items {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 12 | " For version 6.x: Quit when a syntax file was already loaded |
| 13 | if version < 600 |
| 14 | syntax clear |
| 15 | elseif exists("b:current_syntax") |
| 16 | finish |
| 17 | endif |
| 18 | |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 19 | " AFAICT "." should be considered part of the iskeyword. Using iskeywords in |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 20 | " syntax is dicey, so the following code permits the user to |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 21 | " g:sh_isk set to a string : specify iskeyword. |
| 22 | " g:sh_noisk exists : don't change iskeyword |
| 23 | " g:sh_noisk does not exist : (default) append "." to iskeyword |
| 24 | if exists("g:sh_isk") && type(g:sh_isk) == 1 " user specifying iskeyword |
| 25 | exe "setl isk=".g:sh_isk |
| 26 | elseif !exists("g:sh_noisk") " optionally prevent appending '.' to iskeyword |
| 27 | setl isk+=. |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 28 | endif |
| 29 | |
| 30 | " trying to answer the question: which shell is /bin/sh, really? |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 31 | " If the user has not specified any of g:is_kornshell, g:is_bash, g:is_posix, g:is_sh, then guess. |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 32 | if !exists("g:is_kornshell") && !exists("g:is_bash") && !exists("g:is_posix") && !exists("g:is_sh") |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 33 | let s:shell = "" |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 34 | if executable("/bin/sh") |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 35 | let s:shell = resolve("/bin/sh") |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 36 | elseif executable("/usr/bin/sh") |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 37 | let s:shell = resolve("/usr/bin/sh") |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 38 | endif |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 39 | if s:shell =~ 'bash$' |
| 40 | let g:is_bash= 1 |
| 41 | elseif s:shell =~ 'ksh$' |
| 42 | let g:is_kornshell = 1 |
| 43 | elseif s:shell =~ 'dash$' |
| 44 | let g:is_posix = 1 |
| 45 | endif |
| 46 | unlet s:shell |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 47 | endif |
| 48 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 49 | " handling /bin/sh with is_kornshell/is_sh {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 50 | " b:is_sh is set when "#! /bin/sh" is found; |
| 51 | " However, it often is just a masquerade by bash (typically Linux) |
| 52 | " or kornshell (typically workstations with Posix "sh"). |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 53 | " So, when the user sets "g:is_bash", "g:is_kornshell", |
| 54 | " or "g:is_posix", a b:is_sh is converted into b:is_bash/b:is_kornshell, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 55 | " respectively. |
| 56 | if !exists("b:is_kornshell") && !exists("b:is_bash") |
Bram Moolenaar | 7fc904b | 2006-04-13 20:37:35 +0000 | [diff] [blame] | 57 | if exists("g:is_posix") && !exists("g:is_kornshell") |
| 58 | let g:is_kornshell= g:is_posix |
| 59 | endif |
| 60 | if exists("g:is_kornshell") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 61 | let b:is_kornshell= 1 |
| 62 | if exists("b:is_sh") |
| 63 | unlet b:is_sh |
| 64 | endif |
Bram Moolenaar | 7fc904b | 2006-04-13 20:37:35 +0000 | [diff] [blame] | 65 | elseif exists("g:is_bash") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 66 | let b:is_bash= 1 |
| 67 | if exists("b:is_sh") |
| 68 | unlet b:is_sh |
| 69 | endif |
| 70 | else |
| 71 | let b:is_sh= 1 |
| 72 | endif |
| 73 | endif |
| 74 | |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 75 | " set up default g:sh_fold_enabled {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 76 | if !exists("g:sh_fold_enabled") |
| 77 | let g:sh_fold_enabled= 0 |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 78 | elseif g:sh_fold_enabled != 0 && !has("folding") |
| 79 | let g:sh_fold_enabled= 0 |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 80 | echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support" |
| 81 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 82 | if !exists("s:sh_fold_functions") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 83 | let s:sh_fold_functions= and(g:sh_fold_enabled,1) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 84 | endif |
| 85 | if !exists("s:sh_fold_heredoc") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 86 | let s:sh_fold_heredoc = and(g:sh_fold_enabled,2) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 87 | endif |
| 88 | if !exists("s:sh_fold_ifdofor") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 89 | let s:sh_fold_ifdofor = and(g:sh_fold_enabled,4) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 90 | endif |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 91 | if g:sh_fold_enabled && &fdm == "manual" |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 92 | " Given that the user provided g:sh_fold_enabled |
| 93 | " AND g:sh_fold_enabled is manual (usual default) |
| 94 | " implies a desire for syntax-based folding |
| 95 | setl fdm=syntax |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 96 | endif |
| 97 | |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 98 | " sh syntax is case sensitive {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 99 | syn case match |
| 100 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 101 | " Clusters: contains=@... clusters {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 102 | "================================== |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 103 | syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 104 | if exists("b:is_kornshell") |
| 105 | syn cluster ErrorList add=shDTestError |
| 106 | endif |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 107 | syn cluster shArithParenList contains=shArithmetic,shCaseEsac,shComment,shDeref,shDo,shDerefSimple,shEcho,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement,shIf,shFor |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 108 | syn cluster shArithList contains=@shArithParenList,shParenError |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 109 | syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial,shCaseRange |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 110 | syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 111 | syn cluster shCommandSubList contains=shAlias,shArithmetic,shCmdParenRegion,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shOption,shPosnParm,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable |
Bram Moolenaar | 572cb56 | 2005-08-05 21:35:02 +0000 | [diff] [blame] | 112 | syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 113 | syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shEscape,shPosnParm,shCtrlSeq,shSpecial |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 114 | syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPPS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 115 | syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 116 | syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shEscape,shExpr,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 117 | syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 118 | syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 119 | syn cluster shFunctionList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shOption,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shCtrlSeq |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 120 | if exists("b:is_kornshell") || exists("b:is_bash") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 121 | syn cluster shFunctionList add=shRepeat |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 122 | syn cluster shFunctionList add=shDblBrace,shDblParen |
| 123 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 124 | syn cluster shHereBeginList contains=@shCommandSubList |
| 125 | syn cluster shHereList contains=shBeginHere,shHerePayload |
| 126 | syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 127 | syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDeref,shDerefSimple,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial,shAtExpr |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 128 | syn cluster shIfList contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo |
Bram Moolenaar | 0a63ded | 2015-04-15 13:31:24 +0200 | [diff] [blame] | 129 | syn cluster shLoopList contains=@shCaseList,@shErrorList,shCaseEsac,shConditional,shDblBrace,shExpr,shFor,shForPP,shIf,shOption,shSet,shTest,shTestOpr |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 130 | syn cluster shSubShList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 131 | syn cluster shTestList contains=shCharClass,shCommandSub,shComment,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 132 | " Echo: {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 133 | " ==== |
| 134 | " This one is needed INSIDE a CommandSub, so that `echo bla` be correct |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 135 | syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=@shEchoList skipwhite nextgroup=shQuickComment |
| 136 | syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=@shEchoList skipwhite nextgroup=shQuickComment |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 137 | syn match shEchoQuote contained '\%(\\\\\)*\\["`'()]' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 139 | " This must be after the strings, so that ... \" will be correct |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 140 | 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=shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shExDoubleQuote,shDoubleQuote,shCharClass,shCtrlSeq |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 141 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 142 | " Alias: {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | " ===== |
| 144 | if exists("b:is_kornshell") || exists("b:is_bash") |
| 145 | syn match shStatement "\<alias\>" |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 146 | syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+\)\@=" skip="\\$" end="\>\|`" |
| 147 | syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+=\)\@=" skip="\\$" end="=" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 148 | endif |
| 149 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 150 | " Error Codes: {{{1 |
| 151 | " ============ |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 152 | if !exists("g:sh_no_error") |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 153 | syn match shDoError "\<done\>" |
| 154 | syn match shIfError "\<fi\>" |
| 155 | syn match shInError "\<in\>" |
| 156 | syn match shCaseError ";;" |
| 157 | syn match shEsacError "\<esac\>" |
| 158 | syn match shCurlyError "}" |
| 159 | syn match shParenError ")" |
| 160 | syn match shOK '\.\(done\|fi\|in\|esac\)' |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 161 | if exists("b:is_kornshell") |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 162 | syn match shDTestError "]]" |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 163 | endif |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 164 | syn match shTestError "]" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 165 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 166 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 167 | " Options: {{{1 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 168 | " ==================== |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 169 | syn match shOption "\s\zs[-+][-_a-zA-Z0-9#]\+" |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 170 | syn match shOption "\s\zs--[^ \t$`'"|);]\+" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 171 | |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 172 | " File Redirection Highlighted As Operators: {{{1 |
| 173 | "=========================================== |
| 174 | syn match shRedir "\d\=>\(&[-0-9]\)\=" |
| 175 | syn match shRedir "\d\=>>-\=" |
| 176 | syn match shRedir "\d\=<\(&[-0-9]\)\=" |
| 177 | syn match shRedir "\d<<-\=" |
| 178 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 179 | " Operators: {{{1 |
| 180 | " ========== |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 181 | syn match shOperator "<<\|>>" contained |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 182 | syn match shOperator "[!&;|]" contained |
| 183 | syn match shOperator "\[[[^:]\|\]]" contained |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 184 | syn match shOperator "[-=/*+%]\==" skipwhite nextgroup=shPattern |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 185 | syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 186 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 187 | " Subshells: {{{1 |
| 188 | " ========== |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 189 | syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2 nextgroup=shMoreSpecial |
| 190 | syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")" contains=@shSubShList nextgroup=shMoreSpecial |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 191 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 192 | " Tests: {{{1 |
| 193 | "======= |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 194 | syn region shExpr matchgroup=shRange start="\[" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 195 | syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1 |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 196 | syn match shTestOpr contained '[^-+/%]\zs=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 197 | syn match shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 198 | syn match shTestPattern contained '\w\+' |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 199 | syn region shTestDoubleQuote contained start='\%(\%(\\\\\)*\\\)\@<!"' skip=+\\\\\|\\"+ end='"' |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 200 | syn match shTestSingleQuote contained '\\.' |
| 201 | syn match shTestSingleQuote contained "'[^']*'" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 202 | if exists("b:is_kornshell") || exists("b:is_bash") |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 203 | syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList,shComment |
| 204 | syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList,shComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 205 | endif |
| 206 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 207 | " Character Class In Range: {{{1 |
| 208 | " ========================= |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 209 | syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]" |
| 210 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 211 | " Loops: do, if, while, until {{{1 |
| 212 | " ====== |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 213 | if s:sh_fold_ifdofor |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 214 | syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList |
| 215 | syn region shIf fold transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList |
| 216 | syn region shFor fold matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn |
| 217 | syn region shForPP fold matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=shTestOpr |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 218 | else |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 219 | syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList |
| 220 | syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList |
| 221 | syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn |
| 222 | syn region shForPP matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=shTestOpr |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 223 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 224 | if exists("b:is_kornshell") || exists("b:is_bash") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 225 | syn cluster shCaseList add=shRepeat |
| 226 | syn cluster shFunctionList add=shRepeat |
| 227 | syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace |
| 228 | syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace |
| 229 | syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 230 | else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 231 | syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList |
| 232 | syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 233 | endif |
Bram Moolenaar | 572cb56 | 2005-08-05 21:35:02 +0000 | [diff] [blame] | 234 | syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList |
| 235 | syn match shComma contained "," |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 236 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 237 | " Case: case...esac {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 238 | " ==== |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 239 | syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 240 | syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 241 | if s:sh_fold_ifdofor |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 242 | syn region shCase fold contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 243 | syn region shCaseEsac fold matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList |
| 244 | else |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 245 | syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 246 | syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList |
| 247 | endif |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 248 | syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote |
| 249 | if exists("b:is_bash") |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 250 | syn region shCaseExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 251 | elseif !exists("g:sh_no_error") |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 252 | syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained |
| 253 | endif |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 254 | syn region shCaseSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained |
| 255 | syn region shCaseDoubleQuote matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 256 | syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 257 | if exists("b:is_bash") |
| 258 | syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+\]+ contained contains=shCharClass |
| 259 | syn match shCharClass '\[:\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|or\|xdigit\):\]' contained |
| 260 | else |
| 261 | syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+\]+ contained |
| 262 | endif |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 263 | " Misc: {{{1 |
| 264 | "====== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 265 | syn match shWrapLineOperator "\\$" |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 266 | syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 267 | syn match shEscape contained '\%(^\)\@!\%(\\\\\)*\\.' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 268 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 269 | " $() and $(()): {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 270 | " $(..) is not supported by sh (Bourne shell). However, apparently |
| 271 | " some systems (HP?) have as their /bin/sh a (link to) Korn shell |
| 272 | " (ie. Posix compliant shell). /bin/ksh should work for those |
| 273 | " systems too, however, so the following syntax will flag $(..) as |
| 274 | " an Error under /bin/sh. By consensus of vimdev'ers! |
| 275 | if exists("b:is_kornshell") || exists("b:is_bash") |
| 276 | syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 277 | syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList |
Bram Moolenaar | 61d35bd | 2012-03-28 20:51:51 +0200 | [diff] [blame] | 278 | syn region shArithmetic matchgroup=shArithRegion start="\$\[" skip='\\\\\|\\.' end="\]" contains=@shArithList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 279 | syn match shSkipInitWS contained "^\s\+" |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 280 | elseif !exists("g:sh_no_error") |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 281 | syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 282 | endif |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 283 | syn region shCmdParenRegion matchgroup=shCmdSubRegion start="(\ze[^(]" skip='\\\\\|\\.' end=")" contains=@shCommandSubList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 284 | |
| 285 | if exists("b:is_bash") |
| 286 | syn cluster shCommandSubList add=bashSpecialVariables,bashStatement |
| 287 | syn cluster shCaseList add=bashAdminStatement,bashStatement |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 288 | syn keyword bashSpecialVariables contained auto_resume BASH BASH_ALIASES BASH_ALIASES BASH_ARGC BASH_ARGC BASH_ARGV BASH_ARGV BASH_CMDS BASH_CMDS BASH_COMMAND BASH_COMMAND BASH_ENV BASH_EXECUTION_STRING BASH_EXECUTION_STRING BASH_LINENO BASH_LINENO BASHOPTS BASHOPTS BASHPID BASHPID BASH_REMATCH BASH_REMATCH BASH_SOURCE BASH_SOURCE BASH_SUBSHELL BASH_SUBSHELL BASH_VERSINFO BASH_VERSION BASH_XTRACEFD BASH_XTRACEFD CDPATH COLUMNS COLUMNS COMP_CWORD COMP_CWORD COMP_KEY COMP_KEY COMP_LINE COMP_LINE COMP_POINT COMP_POINT COMPREPLY COMPREPLY COMP_TYPE COMP_TYPE COMP_WORDBREAKS COMP_WORDBREAKS COMP_WORDS COMP_WORDS COPROC COPROC DIRSTACK EMACS EMACS ENV ENV EUID FCEDIT FIGNORE FUNCNAME FUNCNAME FUNCNEST FUNCNEST GLOBIGNORE GROUPS histchars HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HISTTIMEFORMAT HISTTIMEFORMAT HOME HOSTFILE HOSTNAME HOSTTYPE IFS IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_CTYPE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_NUMERIC LINENO LINES LINES MACHTYPE MAIL MAILCHECK MAILPATH MAPFILE MAPFILE OLDPWD OPTARG OPTERR OPTIND OSTYPE PATH PIPESTATUS POSIXLY_CORRECT POSIXLY_CORRECT PPID PROMPT_COMMAND PS1 PS2 PS3 PS4 PWD RANDOM READLINE_LINE READLINE_LINE READLINE_POINT READLINE_POINT REPLY SECONDS SHELL SHELL SHELLOPTS SHLVL TIMEFORMAT TIMEOUT TMPDIR TMPDIR UID |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 289 | syn keyword bashStatement chmod clear complete du egrep expr fgrep find gnufind gnugrep grep less ls mkdir mv rm rmdir rpm sed sleep sort strip tail touch |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 290 | syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 291 | syn keyword bashStatement command compgen |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 292 | endif |
| 293 | |
| 294 | if exists("b:is_kornshell") |
| 295 | syn cluster shCommandSubList add=kshSpecialVariables,kshStatement |
| 296 | syn cluster shCaseList add=kshStatement |
| 297 | syn keyword kshSpecialVariables contained CDPATH COLUMNS EDITOR ENV ERRNO FCEDIT FPATH HISTFILE HISTSIZE HOME IFS LINENO LINES MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTIND PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELL TMOUT VISUAL |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 298 | syn keyword kshStatement cat chmod clear cp du egrep expr fgrep find grep killall less ls mkdir mv nice printenv rm rmdir sed sort strip stty tail touch tput |
| 299 | syn keyword kshStatement command setgroups setsenv |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 300 | endif |
| 301 | |
| 302 | syn match shSource "^\.\s" |
| 303 | syn match shSource "\s\.\s" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 304 | "syn region shColon start="^\s*:" end="$" end="\s#"me=e-2 contains=@shColonList |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 305 | "syn region shColon start="^\s*\zs:" end="$" end="\s#"me=e-2 |
| 306 | syn match shColon '^\s*\zs:' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 307 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 308 | " String And Character Constants: {{{1 |
| 309 | "================================ |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 310 | syn match shNumber "-\=\<\d\+\>#\=" |
| 311 | syn match shCtrlSeq "\\\d\d\d\|\\[abcfnrtv0]" contained |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 312 | if exists("b:is_bash") |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 313 | syn match shSpecial "\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 314 | endif |
| 315 | if exists("b:is_bash") |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 316 | syn region shExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 317 | syn region shExDoubleQuote matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,shSpecial |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 318 | elseif !exists("g:sh_no_error") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 319 | syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 320 | syn region shExDoubleQuote matchGroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 321 | endif |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 322 | syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 323 | syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 324 | syn region shDoubleQuote matchgroup=shQuote start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell |
| 325 | syn match shStringSpecial "[^[:print:] \t]" contained |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 326 | syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]" |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 327 | " COMBAK: why is ,shComment on next line??? |
| 328 | syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial,shComment |
| 329 | syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shComment |
| 330 | syn match shMoreSpecial "\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial contained |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 331 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 332 | " Comments: {{{1 |
| 333 | "========== |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 334 | syn cluster shCommentGroup contains=shTodo,@Spell |
| 335 | syn keyword shTodo contained COMBAK FIXME TODO XXX |
| 336 | syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup |
| 337 | syn match shComment "\s\zs#.*$" contains=@shCommentGroup |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 338 | syn match shComment contained "#.*$" contains=@shCommentGroup |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 339 | syn match shQuickComment contained "#.*$" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 340 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 341 | " Here Documents: {{{1 |
| 342 | " ========================================= |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 343 | if version < 600 |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 344 | syn region shHereDoc matchgroup=shHereDoc01 start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shHereDoc01 end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList |
| 345 | syn region shHereDoc matchgroup=shHereDoc02 start="<<-\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shHereDoc02 end="^\s*END[a-zA-Z_0-9]*$" contains=@shDblQuoteList |
| 346 | syn region shHereDoc matchgroup=shHereDoc03 start="<<\s*\**EOF\**" matchgroup=shHereDoc03 end="^EOF$" contains=@shDblQuoteList |
| 347 | syn region shHereDoc matchgroup=shHereDoc04 start="<<-\s*\**EOF\**" matchgroup=shHereDoc04 end="^\s*EOF$" contains=@shDblQuoteList |
| 348 | syn region shHereDoc matchgroup=shHereDoc05 start="<<\s*\**\.\**" matchgroup=shHereDoc05 end="^\.$" contains=@shDblQuoteList |
| 349 | syn region shHereDoc matchgroup=shHereDoc06 start="<<-\s*\**\.\**" matchgroup=shHereDoc06 end="^\s*\.$" contains=@shDblQuoteList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 350 | |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 351 | elseif s:sh_fold_heredoc |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 352 | syn region shHereDoc matchgroup=shHereDoc07 fold start="<<\s*\z([^ \t|]*\)" matchgroup=shHereDoc07 end="^\z1\s*$" contains=@shDblQuoteList |
| 353 | syn region shHereDoc matchgroup=shHereDoc08 fold start="<<\s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc08 end="^\z1\s*$" |
| 354 | syn region shHereDoc matchgroup=shHereDoc09 fold start="<<\s*'\z([^ \t|]*\)'" matchgroup=shHereDoc09 end="^\z1\s*$" |
| 355 | syn region shHereDoc matchgroup=shHereDoc10 fold start="<<-\s*\z([^ \t|]*\)" matchgroup=shHereDoc10 end="^\s*\z1\s*$" contains=@shDblQuoteList |
| 356 | syn region shHereDoc matchgroup=shHereDoc11 fold start="<<-\s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc11 end="^\s*\z1\s*$" |
| 357 | syn region shHereDoc matchgroup=shHereDoc12 fold start="<<-\s*'\z([^ \t|]*\)'" matchgroup=shHereDoc12 end="^\s*\z1\s*$" |
| 358 | syn region shHereDoc matchgroup=shHereDoc13 fold start="<<\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shHereDoc13 end="^\z1\s*$" |
| 359 | syn region shHereDoc matchgroup=shHereDoc14 fold start="<<\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc14 end="^\z1\s*$" |
| 360 | syn region shHereDoc matchgroup=shHereDoc15 fold start="<<-\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shHereDoc15 end="^\s*\z1\s*$" |
| 361 | syn region shHereDoc matchgroup=shHereDoc16 fold start="<<-\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shHereDoc16 end="^\s*\z1\s*$" |
| 362 | syn region shHereDoc matchgroup=shHereDoc17 fold start="<<-\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc17 end="^\s*\z1\s*$" |
| 363 | syn region shHereDoc matchgroup=shHereDoc18 fold start="<<\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shHereDoc18 end="^\z1\s*$" |
| 364 | syn region shHereDoc matchgroup=shHereDoc19 fold start="<<\\\z([^ \t|]*\)" matchgroup=shHereDoc19 end="^\z1\s*$" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 365 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 366 | else |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 367 | syn region shHereDoc matchgroup=shHereDoc20 start="<<\s*\\\=\z([^ \t|]*\)" matchgroup=shHereDoc20 end="^\z1\s*$" contains=@shDblQuoteList |
| 368 | syn region shHereDoc matchgroup=shHereDoc21 start="<<\s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc21 end="^\z1\s*$" |
| 369 | syn region shHereDoc matchgroup=shHereDoc22 start="<<-\s*\z([^ \t|]*\)" matchgroup=shHereDoc22 end="^\s*\z1\s*$" contains=@shDblQuoteList |
| 370 | syn region shHereDoc matchgroup=shHereDoc23 start="<<-\s*'\z([^ \t|]*\)'" matchgroup=shHereDoc23 end="^\s*\z1\s*$" |
| 371 | syn region shHereDoc matchgroup=shHereDoc24 start="<<\s*'\z([^ \t|]*\)'" matchgroup=shHereDoc24 end="^\z1\s*$" |
| 372 | syn region shHereDoc matchgroup=shHereDoc25 start="<<-\s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc25 end="^\s*\z1\s*$" |
| 373 | syn region shHereDoc matchgroup=shHereDoc26 start="<<\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shHereDoc26 end="^\z1\s*$" |
| 374 | syn region shHereDoc matchgroup=shHereDoc27 start="<<-\s*\\\_$\_s*\z([^ \t|]*\)" matchgroup=shHereDoc27 end="^\s*\z1\s*$" |
| 375 | syn region shHereDoc matchgroup=shHereDoc28 start="<<-\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shHereDoc28 end="^\s*\z1\s*$" |
| 376 | syn region shHereDoc matchgroup=shHereDoc29 start="<<\s*\\\_$\_s*'\z([^ \t|]*\)'" matchgroup=shHereDoc29 end="^\z1\s*$" |
| 377 | syn region shHereDoc matchgroup=shHereDoc30 start="<<\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc30 end="^\z1\s*$" |
| 378 | syn region shHereDoc matchgroup=shHereDoc31 start="<<-\s*\\\_$\_s*\"\z([^ \t|]*\)\"" matchgroup=shHereDoc31 end="^\s*\z1\s*$" |
| 379 | syn region shHereDoc matchgroup=shHereDoc32 start="<<\\\z([^ \t|]*\)" matchgroup=shHereDoc32 end="^\z1\s*$" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 380 | endif |
| 381 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 382 | " Here Strings: {{{1 |
| 383 | " ============= |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 384 | " available for: bash; ksh (really should be ksh93 only) but not if its a posix |
| 385 | if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("g:is_posix")) |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 386 | syn match shRedir "<<<" skipwhite nextgroup=shCmdParenRegion |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 387 | endif |
| 388 | |
| 389 | " Identifiers: {{{1 |
| 390 | "============= |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 391 | syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 392 | syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shVarAssign |
| 393 | syn match shVarAssign "=" contained nextgroup=shCmdParenRegion,shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 394 | syn region shAtExpr contained start="@(" end=")" contains=@shIdList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 395 | if exists("b:is_bash") |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 396 | syn region shSetList oneline matchgroup=shSet start="\<\(declare\|typeset\|local\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+#\|=" contains=@shIdList |
| 397 | syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="\ze[;|)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+=" contains=@shIdList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 398 | elseif exists("b:is_kornshell") |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 399 | syn region shSetList oneline matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList |
| 400 | syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 401 | else |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 402 | syn region shSetList oneline matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 403 | endif |
| 404 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 405 | " Functions: {{{1 |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 406 | if !exists("g:is_posix") |
| 407 | syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo |
| 408 | endif |
| 409 | |
| 410 | if exists("b:is_bash") |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 411 | if s:sh_fold_functions |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 412 | syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 413 | syn region shFunctionTwo fold matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 414 | syn region shFunctionThree fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 415 | syn region shFunctionFour fold matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*)" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 416 | else |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 417 | syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList |
| 418 | syn region shFunctionTwo matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained |
| 419 | syn region shFunctionThree matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*(" end=")" contains=@shFunctionList |
| 420 | syn region shFunctionFour matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 421 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 422 | else |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 423 | if s:sh_fold_functions |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 424 | syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 425 | syn region shFunctionTwo fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 426 | syn region shFunctionThree fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 427 | syn region shFunctionFour fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 428 | else |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 429 | syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList |
| 430 | syn region shFunctionTwo matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained |
| 431 | syn region shFunctionThree matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList |
| 432 | syn region shFunctionFour matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 433 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 434 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 435 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 436 | " Parameter Dereferencing: {{{1 |
| 437 | " ======================== |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 438 | syn match shDerefSimple "\$\%(\k\+\|\d\)" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 439 | syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 440 | if !exists("g:sh_no_error") |
| 441 | syn match shDerefWordError "[^}$[]" contained |
| 442 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 443 | syn match shDerefSimple "\$[-#*@!?]" |
| 444 | syn match shDerefSimple "\$\$" |
| 445 | if exists("b:is_bash") || exists("b:is_kornshell") |
| 446 | syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 447 | syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 448 | endif |
| 449 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 450 | " bash: ${!prefix*} and ${#parameter}: {{{1 |
| 451 | " ==================================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 452 | if exists("b:is_bash") |
| 453 | syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 454 | syn match shDerefVar contained "{\@<=!\k\+" nextgroup=@shDerefVarList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 455 | endif |
| 456 | |
| 457 | syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError |
| 458 | syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 459 | syn match shDerefVar contained "{\@<=\k\+" nextgroup=@shDerefVarList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 460 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 461 | " sh ksh bash : ${var[... ]...} array reference: {{{1 |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 462 | syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 463 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 464 | " Special ${parameter OPERATOR word} handling: {{{1 |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 465 | " sh ksh bash : ${parameter:-word} word is default value |
| 466 | " sh ksh bash : ${parameter:=word} assign word as default value |
| 467 | " sh ksh bash : ${parameter:?word} display word if parameter is null |
| 468 | " sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing |
| 469 | " ksh bash : ${parameter#pattern} remove small left pattern |
| 470 | " ksh bash : ${parameter##pattern} remove large left pattern |
| 471 | " ksh bash : ${parameter%pattern} remove small right pattern |
| 472 | " ksh bash : ${parameter%%pattern} remove large right pattern |
| 473 | " bash : ${parameter^pattern} Case modification |
| 474 | " bash : ${parameter^^pattern} Case modification |
| 475 | " bash : ${parameter,pattern} Case modification |
| 476 | " bash : ${parameter,,pattern} Case modification |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 477 | syn cluster shDerefPatternList contains=shDerefPattern,shDerefString |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 478 | if !exists("g:sh_no_error") |
| 479 | syn match shDerefOpError contained ":[[:punct:]]" |
| 480 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 481 | syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList |
| 482 | syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList |
| 483 | if exists("b:is_bash") || exists("b:is_kornshell") |
| 484 | syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList |
| 485 | syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 486 | syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 487 | syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 488 | syn match shDerefEscape contained '\%(\\\\\)*\\.' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 489 | endif |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 490 | if exists("b:is_bash") |
| 491 | syn match shDerefOp contained "[,^]\{1,2}" nextgroup=@shDerefPatternList |
| 492 | endif |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 493 | syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ contains=shStringSpecial |
| 494 | syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 495 | syn match shDerefString contained "\\["']" nextgroup=shDerefPattern |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 496 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 497 | if exists("b:is_bash") |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 498 | " bash : ${parameter:offset} |
| 499 | " bash : ${parameter:offset:length} |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 500 | syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 501 | syn match shDerefPOL contained ":[^}]\+" contains=@shCommandSubList |
| 502 | |
| 503 | " bash : ${parameter//pattern/string} |
| 504 | " bash : ${parameter//pattern} |
| 505 | syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 506 | syn region shDerefPPSleft contained start='.' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList |
| 507 | syn region shDerefPPSright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}' contains=@shCommandSubList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 508 | endif |
| 509 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 510 | " Arithmetic Parenthesized Expressions: {{{1 |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 511 | "syn region shParen matchgroup=shArithRegion start='[^$]\zs(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList |
| 512 | syn region shParen matchgroup=shArithRegion start='\$\@!(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 513 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 514 | " Useful sh Keywords: {{{1 |
| 515 | " =================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 516 | syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait |
| 517 | syn keyword shConditional contained elif else then |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 518 | if !exists("g:sh_no_error") |
| 519 | syn keyword shCondError elif else then |
| 520 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 521 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 522 | " Useful ksh Keywords: {{{1 |
| 523 | " ==================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 524 | if exists("b:is_kornshell") || exists("b:is_bash") |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 525 | syn keyword shStatement autoload bg false fc fg functions getopts hash history integer jobs let nohup printf r stop suspend times true type unalias whence |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 526 | if exists("g:is_posix") |
| 527 | syn keyword shStatement command |
| 528 | else |
| 529 | syn keyword shStatement time |
| 530 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 531 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 532 | " Useful bash Keywords: {{{1 |
| 533 | " ===================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 534 | if exists("b:is_bash") |
| 535 | syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source |
| 536 | else |
| 537 | syn keyword shStatement login newgrp |
| 538 | endif |
| 539 | endif |
| 540 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 541 | " Synchronization: {{{1 |
| 542 | " ================ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 543 | if !exists("sh_minlines") |
| 544 | let sh_minlines = 200 |
| 545 | endif |
| 546 | if !exists("sh_maxlines") |
| 547 | let sh_maxlines = 2 * sh_minlines |
| 548 | endif |
| 549 | exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines |
| 550 | syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>" |
| 551 | syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>" |
| 552 | syn sync match shDoSync grouphere shDo "\<do\>" |
| 553 | syn sync match shDoSync groupthere shDo "\<done\>" |
| 554 | syn sync match shForSync grouphere shFor "\<for\>" |
| 555 | syn sync match shForSync groupthere shFor "\<in\>" |
| 556 | syn sync match shIfSync grouphere shIf "\<if\>" |
| 557 | syn sync match shIfSync groupthere shIf "\<fi\>" |
| 558 | syn sync match shUntilSync grouphere shRepeat "\<until\>" |
| 559 | syn sync match shWhileSync grouphere shRepeat "\<while\>" |
| 560 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 561 | " Default Highlighting: {{{1 |
| 562 | " ===================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 563 | hi def link shArithRegion shShellVariables |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 564 | hi def link shAtExpr shSetList |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 565 | hi def link shBeginHere shRedir |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 566 | hi def link shCaseBar shConditional |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 567 | hi def link shCaseCommandSub shCommandSub |
| 568 | hi def link shCaseDoubleQuote shDoubleQuote |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 569 | hi def link shCaseIn shConditional |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 570 | hi def link shQuote shOperator |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 571 | hi def link shCaseSingleQuote shSingleQuote |
| 572 | hi def link shCaseStart shConditional |
| 573 | hi def link shCmdSubRegion shShellVariables |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 574 | hi def link shColon shComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 575 | hi def link shDerefOp shOperator |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 576 | hi def link shDerefPOL shDerefOp |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 577 | hi def link shDerefPPS shDerefOp |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 578 | hi def link shDeref shShellVariables |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 579 | hi def link shDerefDelim shOperator |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 580 | hi def link shDerefSimple shDeref |
| 581 | hi def link shDerefSpecial shDeref |
| 582 | hi def link shDerefString shDoubleQuote |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 583 | hi def link shDerefVar shDeref |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 584 | hi def link shDoubleQuote shString |
| 585 | hi def link shEcho shString |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 586 | hi def link shEchoDelim shOperator |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 587 | hi def link shEchoQuote shString |
Bram Moolenaar | 83d1b19 | 2015-04-13 14:22:40 +0200 | [diff] [blame] | 588 | hi def link shForPP shLoop |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 589 | hi def link shEmbeddedEcho shString |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 590 | hi def link shEscape shCommandSub |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 591 | hi def link shExDoubleQuote shDoubleQuote |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 592 | hi def link shExSingleQuote shSingleQuote |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 593 | hi def link shFunction Function |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 594 | hi def link shHereDoc shString |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 595 | hi def link shHerePayload shHereDoc |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 596 | hi def link shLoop shStatement |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 597 | hi def link shMoreSpecial shSpecial |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 598 | hi def link shOption shCommandSub |
| 599 | hi def link shPattern shString |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 600 | hi def link shParen shArithmetic |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 601 | hi def link shPosnParm shShellVariables |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 602 | hi def link shQuickComment shComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 603 | hi def link shRange shOperator |
| 604 | hi def link shRedir shOperator |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 605 | hi def link shSetListDelim shOperator |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 606 | hi def link shSetOption shOption |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 607 | hi def link shSingleQuote shString |
| 608 | hi def link shSource shOperator |
| 609 | hi def link shStringSpecial shSpecial |
| 610 | hi def link shSubShRegion shOperator |
| 611 | hi def link shTestOpr shConditional |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 612 | hi def link shTestPattern shString |
| 613 | hi def link shTestDoubleQuote shString |
| 614 | hi def link shTestSingleQuote shString |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 615 | hi def link shVariable shSetList |
| 616 | hi def link shWrapLineOperator shOperator |
| 617 | |
| 618 | if exists("b:is_bash") |
| 619 | hi def link bashAdminStatement shStatement |
| 620 | hi def link bashSpecialVariables shShellVariables |
| 621 | hi def link bashStatement shStatement |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 622 | hi def link shFunctionParen Delimiter |
| 623 | hi def link shFunctionDelim Delimiter |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 624 | hi def link shCharClass shSpecial |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 625 | endif |
| 626 | if exists("b:is_kornshell") |
| 627 | hi def link kshSpecialVariables shShellVariables |
| 628 | hi def link kshStatement shStatement |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 629 | hi def link shFunctionParen Delimiter |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 630 | endif |
| 631 | |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 632 | if !exists("g:sh_no_error") |
| 633 | hi def link shCaseError Error |
| 634 | hi def link shCondError Error |
| 635 | hi def link shCurlyError Error |
| 636 | hi def link shDerefError Error |
| 637 | hi def link shDerefOpError Error |
| 638 | hi def link shDerefWordError Error |
| 639 | hi def link shDoError Error |
| 640 | hi def link shEsacError Error |
| 641 | hi def link shIfError Error |
| 642 | hi def link shInError Error |
| 643 | hi def link shParenError Error |
| 644 | hi def link shTestError Error |
| 645 | if exists("b:is_kornshell") |
| 646 | hi def link shDTestError Error |
| 647 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 648 | endif |
| 649 | |
| 650 | hi def link shArithmetic Special |
| 651 | hi def link shCharClass Identifier |
| 652 | hi def link shSnglCase Statement |
| 653 | hi def link shCommandSub Special |
| 654 | hi def link shComment Comment |
| 655 | hi def link shConditional Conditional |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 656 | hi def link shCtrlSeq Special |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 657 | hi def link shExprRegion Delimiter |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 658 | hi def link shFunctionKey Function |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 659 | hi def link shFunctionName Function |
| 660 | hi def link shNumber Number |
| 661 | hi def link shOperator Operator |
| 662 | hi def link shRepeat Repeat |
| 663 | hi def link shSet Statement |
| 664 | hi def link shSetList Identifier |
| 665 | hi def link shShellVariables PreProc |
| 666 | hi def link shSpecial Special |
| 667 | hi def link shStatement Statement |
| 668 | hi def link shString String |
| 669 | hi def link shTodo Todo |
| 670 | hi def link shAlias Identifier |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 671 | hi def link shHereDoc01 shRedir |
| 672 | hi def link shHereDoc02 shRedir |
| 673 | hi def link shHereDoc03 shRedir |
| 674 | hi def link shHereDoc04 shRedir |
| 675 | hi def link shHereDoc05 shRedir |
| 676 | hi def link shHereDoc06 shRedir |
| 677 | hi def link shHereDoc07 shRedir |
| 678 | hi def link shHereDoc08 shRedir |
| 679 | hi def link shHereDoc09 shRedir |
| 680 | hi def link shHereDoc10 shRedir |
| 681 | hi def link shHereDoc11 shRedir |
| 682 | hi def link shHereDoc12 shRedir |
| 683 | hi def link shHereDoc13 shRedir |
| 684 | hi def link shHereDoc14 shRedir |
| 685 | hi def link shHereDoc15 shRedir |
| 686 | hi def link shHereDoc16 shRedir |
| 687 | hi def link shHereDoc17 shRedir |
| 688 | hi def link shHereDoc18 shRedir |
| 689 | hi def link shHereDoc19 shRedir |
| 690 | hi def link shHereDoc20 shRedir |
| 691 | hi def link shHereDoc21 shRedir |
| 692 | hi def link shHereDoc22 shRedir |
| 693 | hi def link shHereDoc23 shRedir |
| 694 | hi def link shHereDoc24 shRedir |
| 695 | hi def link shHereDoc25 shRedir |
| 696 | hi def link shHereDoc26 shRedir |
| 697 | hi def link shHereDoc27 shRedir |
| 698 | hi def link shHereDoc28 shRedir |
| 699 | hi def link shHereDoc29 shRedir |
| 700 | hi def link shHereDoc30 shRedir |
| 701 | hi def link shHereDoc31 shRedir |
| 702 | hi def link shHereDoc32 shRedir |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 703 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 704 | " Set Current Syntax: {{{1 |
| 705 | " =================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 706 | if exists("b:is_bash") |
| 707 | let b:current_syntax = "bash" |
| 708 | elseif exists("b:is_kornshell") |
| 709 | let b:current_syntax = "ksh" |
| 710 | else |
| 711 | let b:current_syntax = "sh" |
| 712 | endif |
| 713 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 714 | " vim: ts=16 fdm=marker |