7
|
1 " Vim syntax file
|
|
2 " Language: shell (sh) Korn shell (ksh) bash (sh)
|
|
3 " Maintainer: Dr. Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz>
|
|
4 " Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int>
|
167
|
5 " Last Change: Feb 16, 2005
|
|
6 " Version: 72
|
7
|
7 " URL: http://www.erols.com/astronaut/vim/index.html#vimlinks_syntax
|
|
8 "
|
22
|
9 " Using the following VIM variables: {{{1
|
7
|
10 " b:is_kornshell if defined, enhance with kornshell syntax
|
|
11 " b:is_bash if defined, enhance with bash syntax
|
|
12 " is_kornshell if neither b:is_kornshell or b:is_bash is
|
|
13 " defined, then if is_kornshell is set
|
|
14 " b:is_kornshell is default
|
|
15 " is_bash if none of the previous three variables are
|
|
16 " defined, then if is_bash is set b:is_bash is default
|
|
17 " g:sh_fold_enabled if non-zero, syntax folding is enabled
|
|
18 " sh_minlines sets up syn sync minlines (default: 200)
|
|
19 " sh_maxlines sets up syn sync maxlines (default: twice sh_minlines)
|
|
20 "
|
|
21 " This file includes many ideas from Éric Brunet (eric.brunet@ens.fr)
|
|
22
|
22
|
23 " For version 5.x: Clear all syntax items {{{1
|
7
|
24 " For version 6.x: Quit when a syntax file was already loaded
|
|
25 if version < 600
|
|
26 syntax clear
|
|
27 elseif exists("b:current_syntax")
|
|
28 finish
|
|
29 endif
|
|
30
|
22
|
31 " handling /bin/sh with is_kornshell/is_sh {{{1
|
7
|
32 " b:is_sh is set when "#! /bin/sh" is found;
|
|
33 " However, it often is just a masquerade by bash (typically Linux)
|
|
34 " or kornshell (typically workstations with Posix "sh").
|
|
35 " So, when the user sets "is_bash" or "is_kornshell",
|
|
36 " a b:is_sh is converted into b:is_bash/b:is_kornshell,
|
|
37 " respectively.
|
|
38 if !exists("b:is_kornshell") && !exists("b:is_bash")
|
|
39 if exists("is_kornshell")
|
|
40 let b:is_kornshell= 1
|
|
41 if exists("b:is_sh")
|
|
42 unlet b:is_sh
|
|
43 endif
|
|
44 elseif exists("is_bash")
|
|
45 let b:is_bash= 1
|
|
46 if exists("b:is_sh")
|
|
47 unlet b:is_sh
|
|
48 endif
|
|
49 else
|
|
50 let b:is_sh= 1
|
|
51 endif
|
|
52 endif
|
|
53
|
|
54 if !exists("g:sh_fold_enabled")
|
|
55 let g:sh_fold_enabled= 0
|
36
|
56 elseif g:sh_fold_enabled != 0 && !has("folding")
|
|
57 let g:sh_fold_enabled= 0
|
|
58 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; re-compile vim for +fold support"
|
7
|
59 endif
|
|
60
|
|
61 " sh syntax is case sensitive
|
|
62 syn case match
|
|
63
|
22
|
64 " Clusters: contains=@... clusters {{{1
|
7
|
65 "==================================
|
167
|
66 syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shSpecial
|
7
|
67 syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,bkshFunction,shSpecial
|
|
68 syn cluster shColonList contains=@shCaseList
|
167
|
69 syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shNumber,shOperator,shPosnParm,shSpecial,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest
|
7
|
70 syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shSpecial,shPosnParm
|
|
71 syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError
|
|
72 syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError
|
167
|
73 syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shSingleQuote,shDoubleQuote,shSpecial
|
|
74 syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shSingleQuote,shDoubleQuote,shSpecial,shExpr,shDblBrace,shDeref,shDerefSimple
|
119
|
75 syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest
|
7
|
76 syn cluster shFunctionList contains=@shCaseList,shOperator
|
|
77 syn cluster shHereBeginList contains=@shCommandSubList
|
|
78 syn cluster shHereList contains=shBeginHere,shHerePayload
|
|
79 syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload
|
167
|
80 syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shIdWhiteSpace,shDeref,shDerefSimple,shSpecial,shRedir,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr
|
119
|
81 syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest
|
7
|
82 syn cluster shSubShList contains=@shCaseList
|
167
|
83 syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shDoubleQuote,shExpr,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shSpecial,shTestOpr,shTest
|
7
|
84
|
|
85
|
22
|
86 " Echo: {{{1
|
7
|
87 " ====
|
|
88 " This one is needed INSIDE a CommandSub, so that `echo bla` be correct
|
|
89 syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList
|
|
90 syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList
|
|
91
|
|
92 " This must be after the strings, so that bla \" be correct
|
167
|
93 syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shSpecial,shOperator,shDoubleQuote,shCharClass
|
7
|
94
|
22
|
95 " Alias: {{{1
|
7
|
96 " =====
|
|
97 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
98 syn match shStatement "\<alias\>"
|
|
99 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\w\+\)\@=" skip="\\$" end="\>\|`"
|
|
100 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\w\+=\)\@=" skip="\\$" end="="
|
|
101 endif
|
|
102
|
22
|
103 " Error Codes: {{{1
|
|
104 " ============
|
7
|
105 syn match shDoError "\<done\>"
|
|
106 syn match shIfError "\<fi\>"
|
|
107 syn match shInError "\<in\>"
|
|
108 syn match shCaseError ";;"
|
|
109 syn match shEsacError "\<esac\>"
|
|
110 syn match shCurlyError "}"
|
|
111 syn match shParenError ")"
|
|
112 if exists("b:is_kornshell")
|
|
113 syn match shDTestError "]]"
|
|
114 endif
|
|
115 syn match shTestError "]"
|
|
116
|
22
|
117 " Options Interceptor: {{{1
|
|
118 " ====================
|
7
|
119 syn match shOption "\s[\-+][a-zA-Z0-9]\+\>"ms=s+1
|
|
120 syn match shOption "\s--\S\+"ms=s+1
|
|
121
|
22
|
122 " Operators: {{{1
|
|
123 " ==========
|
7
|
124 syn match shOperator "[!&;|]"
|
|
125 syn match shOperator "\[[[^:]\|\]]"
|
|
126 syn match shOperator "!\==" skipwhite nextgroup=shPattern
|
167
|
127 syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shDoubleQuote,shDeref
|
7
|
128
|
22
|
129 " Subshells: {{{1
|
|
130 " ==========
|
7
|
131 syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2
|
|
132 syn region shSubSh transparent matchgroup=shSubShRegion start="(" end=")" contains=@shSubShList
|
|
133
|
22
|
134 " Tests: {{{1
|
|
135 "=======
|
7
|
136 "syn region shExpr transparent matchgroup=shRange start="\[" skip=+\\\\\|\\$+ end="\]" contains=@shTestList
|
|
137 syn region shExpr matchgroup=shRange start="\[" skip=+\\\\\|\\$+ end="\]" contains=@shTestList
|
119
|
138 syn region shTest transparent matchgroup=shStatement start="\<test\>" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1
|
7
|
139 syn match shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!=<>]"
|
|
140 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
141 syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList
|
|
142 syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList
|
|
143 endif
|
|
144
|
22
|
145 " Character Class In Range: {{{1
|
|
146 " =========================
|
7
|
147 syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
|
|
148
|
22
|
149 " Loops: do, if, while, until {{{1
|
|
150 " ======
|
7
|
151 syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
|
|
152 syn region shIf transparent matchgroup=shConditional start="\<if\>" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen
|
|
153 syn region shFor matchgroup=shLoop start="\<for\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen
|
|
154 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
155 syn cluster shCaseList add=shRepeat
|
|
156 syn region shRepeat matchgroup=shLoop start="\<while\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
|
|
157 syn region shRepeat matchgroup=shLoop start="\<until\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
|
|
158 syn region shCaseEsac matchgroup=shConditional start="\<select\>" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
|
|
159 else
|
|
160 syn region shRepeat matchgroup=shLoop start="\<while\>" end="\<do\>"me=e-2 contains=@shLoopList
|
|
161 syn region shRepeat matchgroup=shLoop start="\<until\>" end="\<do\>"me=e-2 contains=@shLoopList
|
|
162 endif
|
|
163
|
22
|
164 " Case: case...esac {{{1
|
7
|
165 " ====
|
167
|
166 syn match shCaseBar contained skipwhite "[^|"`'()]\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
|
7
|
167 syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar
|
|
168 syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="[^$()]\{-})"ms=s,hs=e end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,,shComment
|
|
169 syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
|
167
|
170 syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
|
|
171 if exists("b:is_bash")
|
|
172 syn region shCaseExSingleQuote matchgroup=shOperator start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
173 else
|
|
174 syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
175 endif
|
|
176 syn region shCaseSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
7
|
177 syn region shCaseDoubleQuote matchgroup=shOperator start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
178 syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained
|
|
179
|
22
|
180 " Misc: {{{1
|
|
181 "======
|
7
|
182 syn match shWrapLineOperator "\\$"
|
|
183 syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
|
|
184
|
22
|
185 " $() and $(()): {{{1
|
7
|
186 " $(..) is not supported by sh (Bourne shell). However, apparently
|
|
187 " some systems (HP?) have as their /bin/sh a (link to) Korn shell
|
|
188 " (ie. Posix compliant shell). /bin/ksh should work for those
|
|
189 " systems too, however, so the following syntax will flag $(..) as
|
|
190 " an Error under /bin/sh. By consensus of vimdev'ers!
|
|
191 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
192 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
|
|
193 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shCommandSubList
|
|
194 syn match shSkipInitWS contained "^\s\+"
|
|
195 else
|
167
|
196 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
|
7
|
197 endif
|
|
198
|
|
199 if exists("b:is_bash")
|
|
200 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
|
|
201 syn cluster shCaseList add=bashAdminStatement,bashStatement
|
|
202 syn keyword bashSpecialVariables contained BASH BASH_ENV BASH_VERSINFO BASH_VERSION CDPATH DIRSTACK EUID FCEDIT FIGNORE GLOBIGNORE GROUPS HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HOME HOSTFILE HOSTNAME HOSTTYPE IFS IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_MESSAGES LINENO MACHTYPE MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTERR OPTIND OSTYPE PATH PIPESTATUS PPID PROMPT_COMMAND PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELLOPTS SHLVL TIMEFORMAT TIMEOUT UID auto_resume histchars
|
|
203 syn keyword bashStatement chmod clear complete du egrep expr fgrep find gnufind gnugrep grep install less ls mkdir mv rm rmdir rpm sed sleep sort strip tail touch
|
|
204 syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop
|
|
205 endif
|
|
206
|
|
207 if exists("b:is_kornshell")
|
|
208 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
|
|
209 syn cluster shCaseList add=kshStatement
|
|
210 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
|
|
211 syn keyword kshStatement cat chmod clear cp du egrep expr fgrep find grep install killall less ls mkdir mv nice printenv rm rmdir sed sort strip stty tail touch tput
|
|
212 endif
|
|
213
|
|
214 syn match shSource "^\.\s"
|
|
215 syn match shSource "\s\.\s"
|
|
216 syn region shColon start="^\s*:" end="$\|" end="#"me=e-1 contains=@shColonList
|
|
217
|
22
|
218 " String And Character Constants: {{{1
|
|
219 "================================
|
7
|
220 syn match shNumber "-\=\<\d\+\>"
|
167
|
221 if exists("b:is_bash")
|
|
222 syn match shSpecial "\\\o\o\o\|\\x\x\x\|\\c.\|\\[abefnrtv]" contained
|
|
223 else
|
|
224 syn match shSpecial "\\\d\d\d\|\\[abcfnrtv0]" contained
|
|
225 endif
|
|
226 if exists("b:is_bash")
|
|
227 syn region shExSingleQuote matchgroup=shOperator start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
|
|
228 else
|
|
229 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
|
|
230 endif
|
7
|
231 syn region shSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial
|
|
232 syn region shDoubleQuote matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
|
|
233 syn match shStringSpecial "[^[:print:]]" contained
|
|
234 syn match shSpecial "\\[\\\"\'`$()#]"
|
|
235
|
22
|
236 " Comments: {{{1
|
|
237 "==========
|
7
|
238 syn cluster shCommentGroup contains=shTodo,@Spell
|
|
239 syn keyword shTodo contained TODO
|
|
240 syn match shComment "#.*$" contains=@shCommentGroup
|
|
241
|
22
|
242 " File Redirection Highlighted As Operators: {{{1
|
|
243 "===========================================
|
7
|
244 syn match shRedir "\d\=>\(&[-0-9]\)\="
|
|
245 syn match shRedir "\d\=>>-\="
|
|
246 syn match shRedir "\d\=<\(&[-0-9]\)\="
|
|
247 syn match shRedir "\d<<-\="
|
|
248
|
22
|
249 " Here Documents: {{{1
|
|
250 " =========================================
|
7
|
251 if version < 600
|
|
252 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
|
|
253 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^\s*END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
|
|
254 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
|
|
255 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
|
|
256 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
|
|
257 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
|
|
258
|
|
259 elseif g:sh_fold_enabled
|
|
260
|
|
261 if v:version > 602 || (v:version == 602 && has("patch219"))
|
|
262 syn region shHereDoc fold start="\(<<\s*\\\=\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereListDQ keepend
|
|
263 syn region shHereDoc fold start="\(<<\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
264 syn region shHereDoc fold start="\(<<\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
265 syn region shHereDoc fold start="\(<<\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
266 syn region shHereDoc fold start="\(<<\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
267 syn region shHereDoc fold start="\(<<\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereList keepend
|
|
268 syn region shHereDoc fold start="\(<<-\s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
269 syn region shHereDoc fold start="\(<<-\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereListDQ keepend
|
|
270 syn region shHereDoc fold start="\(<<-\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereList keepend
|
|
271 syn region shHereDoc fold start="\(<<-\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
272 syn region shHereDoc fold start="\(<<-\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
273 syn region shHereDoc fold start="\(<<-\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
274 else
|
|
275 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z(\S*\)" matchgroup=shRedir end="^\z1$" contains=@shDblQuoteList
|
|
276 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
277 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
278 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$" contains=@shDblQuoteList
|
|
279 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
280 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
281 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1$"
|
|
282 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
283 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
284 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$"
|
|
285 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
286 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
287 endif
|
|
288 else
|
|
289 if v:version > 602 || (v:version == 602 && has("patch219"))
|
|
290 syn region shHereDoc start="\(<<\s*\\\=\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereList keepend
|
|
291 syn region shHereDoc start="\(<<\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereListDQ keepend
|
|
292 syn region shHereDoc start="\(<<\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
293 syn region shHereDoc start="\(<<\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
294 syn region shHereDoc start="\(<<\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
295 syn region shHereDoc start="\(<<\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereList keepend
|
|
296 syn region shHereDoc start="\(<<-\s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
297 syn region shHereDoc start="\(<<-\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereListDQ keepend
|
|
298 syn region shHereDoc start="\(<<-\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereList keepend
|
|
299 syn region shHereDoc start="\(<<-\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
300 syn region shHereDoc start="\(<<-\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
301 syn region shHereDoc start="\(<<-\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
119
|
302 syn match shHerePayload "^.*$" contained skipnl nextgroup=shHerePayload contains=@shDblQuoteList
|
|
303 syn match shBeginLine ".*$" contained skipnl nextgroup=shHerePayload contains=@shCommandSubList
|
|
304 syn match shBeginHere "<<-\=\s*\S\+" contained nextgroup=shBeginLine
|
7
|
305 else
|
|
306 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\=\z(\S*\)" matchgroup=shRedir end="^\z1$" contains=@shDblQuoteList
|
|
307 syn region shHereDoc matchgroup=shRedir start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
308 syn region shHereDoc matchgroup=shRedir start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$" contains=@shDblQuoteList
|
|
309 syn region shHereDoc matchgroup=shRedir start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
310 syn region shHereDoc matchgroup=shRedir start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
311 syn region shHereDoc matchgroup=shRedir start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
312 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1$"
|
|
313 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$"
|
|
314 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
315 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
316 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
317 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
318 endif
|
|
319 endif
|
|
320
|
22
|
321 " Here Strings: {{{1
|
|
322 " =============
|
|
323 if exists("b:is_bash")
|
|
324 syn match shRedir "<<<"
|
|
325 endif
|
|
326
|
|
327 " Identifiers: {{{1
|
|
328 "=============
|
7
|
329 syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier
|
|
330 syn match shIdWhiteSpace contained "\s"
|
167
|
331 syn match shSetIdentifier contained "=" nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shSingleQuote,shExSingleQuote
|
7
|
332 if exists("b:is_bash")
|
119
|
333 syn region shSetList matchgroup=shSet start="\<\(declare\|typeset\|local\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="#\|="me=e-1 contains=@shIdList
|
|
334 syn region shSetList matchgroup=shSet start="\<set\>[^/]"me=e-1 end="$" end="\\ze[|)]" matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
|
7
|
335 syn match shSet "\<\(declare\|typeset\|local\|export\|set\|unset\)$"
|
|
336 elseif exists("b:is_kornshell")
|
119
|
337 syn region shSetList matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
|
|
338 syn region shSetList matchgroup=shSet start="\<set\>\ze[^/]" end="$\|\ze[})]" matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
|
7
|
339 syn match shSet "\<\(typeset\|set\|export\|unset\)$"
|
|
340 else
|
119
|
341 syn region shSetList matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$\|\ze[|)]" matchgroup=shOperator end="[;&]" matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
|
7
|
342 syn match shStatement "\<\(set\|export\|unset\)$"
|
|
343 endif
|
|
344
|
22
|
345 " Functions: {{{1
|
7
|
346 " handles functions which start: Function () {
|
|
347 " Apparently Bourne shell accepts functions too,
|
|
348 " even though it isn't documented by my man pages
|
|
349 " for it.
|
|
350 syn cluster shCommandSubList add=bkshFunction
|
|
351 if g:sh_fold_enabled
|
|
352 syn region bkshFunctionBody transparent fold matchgroup=Delimiter start="^\s*\<\h\w*\>\s*()\s*{" end="}" contains=bkshFunction,bkshFunctionDelim,@shFunctionList
|
|
353 else
|
|
354 syn region bkshFunctionBody transparent matchgroup=Delimiter start="^\s*\<\h\w*\>\s*()\s*{" end="}" contains=bkshFunction,bkshFunctionDelim,@shFunctionList
|
|
355 endif
|
|
356 syn match bkshFunction "^\s*\<\h\w*\>\s*()" skipwhite skipnl contains=bkshFunctionParen
|
|
357 syn match bkshFunctionParen "[()]" contained
|
|
358 syn match bkshFunctionDelim "[{}]" contained
|
|
359
|
22
|
360 " Parameter Dereferencing: {{{1
|
|
361 " ========================
|
36
|
362 syn match shDerefSimple "\$\%(\h\w*\|\d\)"
|
7
|
363 syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray
|
|
364 syn match shDerefWordError "[^}$[]" contained
|
|
365 syn match shDerefSimple "\$[-#*@!?]"
|
|
366 syn match shDerefSimple "\$\$"
|
|
367 if exists("b:is_bash") || exists("b:is_kornshell")
|
|
368 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
|
|
369 endif
|
|
370
|
22
|
371 " bash: ${!prefix*} and ${#parameter}: {{{1
|
|
372 " ====================================
|
7
|
373 if exists("b:is_bash")
|
|
374 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp
|
|
375 syn match shDerefVar contained "{\@<=!\w\+" nextgroup=@shDerefVarList
|
|
376 endif
|
|
377
|
|
378 syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError
|
|
379 syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp
|
|
380 syn match shDerefVar contained "{\@<=\w\+" nextgroup=@shDerefVarList
|
|
381
|
22
|
382 " sh ksh bash : ${var[... ]...} array reference: {{{1
|
7
|
383 syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError
|
|
384
|
22
|
385 " Special ${parameter OPERATOR word} handling: {{{1
|
7
|
386 " sh ksh bash : ${parameter:-word} word is default value
|
|
387 " sh ksh bash : ${parameter:=word} assign word as default value
|
|
388 " sh ksh bash : ${parameter:?word} display word if parameter is null
|
|
389 " sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing
|
|
390 " ksh bash : ${parameter#pattern} remove small left pattern
|
|
391 " ksh bash : ${parameter##pattern} remove large left pattern
|
|
392 " ksh bash : ${parameter%pattern} remove small right pattern
|
|
393 " ksh bash : ${parameter%%pattern} remove large right pattern
|
|
394 syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
|
|
395 syn match shDerefOpError contained ":[[:punct:]]"
|
|
396 syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList
|
|
397 syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList
|
|
398 if exists("b:is_bash") || exists("b:is_kornshell")
|
|
399 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList
|
|
400 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
|
|
401 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub nextgroup=shDerefPattern
|
|
402 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
|
|
403 endif
|
|
404 syn region shDerefString contained matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial
|
|
405 syn region shDerefString contained matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
|
|
406 syn match shDerefString contained "\\["']"
|
|
407
|
|
408 " bash : ${parameter:offset}
|
|
409 " bash : ${parameter:offset:length}
|
|
410 " bash : ${parameter//pattern/string}
|
|
411 " bash : ${parameter//pattern}
|
|
412 if exists("b:is_bash")
|
|
413 syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL
|
|
414 syn match shDerefPOL contained ":[^}]\{1,}" contains=@shCommandSubList
|
|
415 syn match shDerefOp contained "/\{1,2}" nextgroup=shDerefPat
|
|
416 syn match shDerefPat contained "[^/}]\{1,}" nextgroup=shDerefPatStringOp
|
|
417 syn match shDerefPatStringOp contained "/" nextgroup=shDerefPatString
|
|
418 syn match shDerefPatString contained "[^}]\{1,}"
|
|
419 endif
|
|
420
|
22
|
421 " Useful sh Keywords: {{{1
|
|
422 " ===================
|
7
|
423 syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
|
|
424 syn keyword shConditional contained elif else then
|
|
425 syn keyword shCondError elif else then
|
|
426
|
22
|
427 " Useful ksh Keywords: {{{1
|
|
428 " ====================
|
7
|
429 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
430 syn keyword shFunction function
|
|
431 syn keyword shStatement autoload bg false fc fg functions getopts hash history integer jobs let nohup print printf r stop suspend time times true type unalias whence
|
|
432
|
22
|
433 " Useful bash Keywords: {{{1
|
|
434 " =====================
|
7
|
435 if exists("b:is_bash")
|
|
436 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
|
|
437 else
|
|
438 syn keyword shStatement login newgrp
|
|
439 endif
|
|
440 endif
|
|
441
|
22
|
442 " Synchronization: {{{1
|
|
443 " ================
|
7
|
444 if !exists("sh_minlines")
|
|
445 let sh_minlines = 200
|
|
446 endif
|
|
447 if !exists("sh_maxlines")
|
|
448 let sh_maxlines = 2 * sh_minlines
|
|
449 endif
|
|
450 exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
|
|
451 syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
|
|
452 syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
|
|
453 syn sync match shDoSync grouphere shDo "\<do\>"
|
|
454 syn sync match shDoSync groupthere shDo "\<done\>"
|
|
455 syn sync match shForSync grouphere shFor "\<for\>"
|
|
456 syn sync match shForSync groupthere shFor "\<in\>"
|
|
457 syn sync match shIfSync grouphere shIf "\<if\>"
|
|
458 syn sync match shIfSync groupthere shIf "\<fi\>"
|
|
459 syn sync match shUntilSync grouphere shRepeat "\<until\>"
|
|
460 syn sync match shWhileSync grouphere shRepeat "\<while\>"
|
|
461
|
22
|
462 " Default Highlighting: {{{1
|
|
463 " =====================
|
7
|
464 hi def link shArithRegion shShellVariables
|
167
|
465 hi def link shBeginHere shRedir
|
7
|
466 hi def link shCaseBar shConditional
|
|
467 hi def link shCaseCommandSub shCommandSub
|
|
468 hi def link shCaseDoubleQuote shDoubleQuote
|
167
|
469 hi def link shCaseIn shConditional
|
7
|
470 hi def link shCaseSingleQuote shSingleQuote
|
|
471 hi def link shCaseStart shConditional
|
|
472 hi def link shCmdSubRegion shShellVariables
|
|
473 hi def link shColon shStatement
|
167
|
474 hi def link shDerefOp shOperator
|
|
475 hi def link shDerefPatStringOp shDerefOp
|
|
476 hi def link shDerefPatString shDerefPattern
|
|
477 hi def link shDerefPOL shDerefOp
|
7
|
478 hi def link shDeref shShellVariables
|
|
479 hi def link shDerefSimple shDeref
|
|
480 hi def link shDerefSpecial shDeref
|
|
481 hi def link shDerefString shDoubleQuote
|
167
|
482 hi def link shDerefVar shDeref
|
7
|
483 hi def link shDoubleQuote shString
|
|
484 hi def link shEcho shString
|
|
485 hi def link shEmbeddedEcho shString
|
167
|
486 hi def link shExSingleQuote shSingleQuote
|
7
|
487 hi def link shHereDoc shString
|
167
|
488 hi def link shHerePayload shHereDoc
|
7
|
489 hi def link shLoop shStatement
|
|
490 hi def link shOption shCommandSub
|
|
491 hi def link shPattern shString
|
|
492 hi def link shPosnParm shShellVariables
|
|
493 hi def link shRange shOperator
|
|
494 hi def link shRedir shOperator
|
|
495 hi def link shSingleQuote shString
|
|
496 hi def link shSource shOperator
|
|
497 hi def link shStringSpecial shSpecial
|
|
498 hi def link shSubShRegion shOperator
|
|
499 hi def link shTestOpr shConditional
|
|
500 hi def link shVariable shSetList
|
|
501 hi def link shWrapLineOperator shOperator
|
|
502
|
|
503 if exists("b:is_bash")
|
|
504 hi def link bashAdminStatement shStatement
|
|
505 hi def link bashSpecialVariables shShellVariables
|
|
506 hi def link bashStatement shStatement
|
|
507 hi def link bkshFunction Function
|
|
508 hi def link bkshFunctionParen Delimiter
|
|
509 hi def link bkshFunctionDelim Delimiter
|
|
510 endif
|
|
511 if exists("b:is_kornshell")
|
|
512 hi def link kshSpecialVariables shShellVariables
|
|
513 hi def link kshStatement shStatement
|
|
514 hi def link bkshFunction Function
|
|
515 hi def link bkshFunctionParen Delimiter
|
|
516 endif
|
|
517
|
|
518 hi def link shCaseError Error
|
|
519 hi def link shCondError Error
|
|
520 hi def link shCurlyError Error
|
|
521 hi def link shDerefError Error
|
|
522 hi def link shDerefOpError Error
|
|
523 hi def link shDerefWordError Error
|
|
524 hi def link shDoError Error
|
|
525 hi def link shEsacError Error
|
|
526 hi def link shIfError Error
|
|
527 hi def link shInError Error
|
|
528 hi def link shParenError Error
|
|
529 hi def link shTestError Error
|
|
530 if exists("b:is_kornshell")
|
|
531 hi def link shDTestError Error
|
|
532 endif
|
|
533
|
|
534 hi def link shArithmetic Special
|
|
535 hi def link shCharClass Identifier
|
|
536 hi def link shSnglCase Statement
|
|
537 hi def link shCommandSub Special
|
|
538 hi def link shComment Comment
|
|
539 hi def link shConditional Conditional
|
|
540 hi def link shExprRegion Delimiter
|
|
541 hi def link shFunction Function
|
|
542 hi def link shFunctionName Function
|
|
543 hi def link shNumber Number
|
|
544 hi def link shOperator Operator
|
|
545 hi def link shRepeat Repeat
|
|
546 hi def link shSet Statement
|
|
547 hi def link shSetList Identifier
|
|
548 hi def link shShellVariables PreProc
|
|
549 hi def link shSpecial Special
|
|
550 hi def link shStatement Statement
|
|
551 hi def link shString String
|
|
552 hi def link shTodo Todo
|
|
553 hi def link shAlias Identifier
|
|
554
|
22
|
555 " Set Current Syntax: {{{1
|
|
556 " ===================
|
7
|
557 if exists("b:is_bash")
|
|
558 let b:current_syntax = "bash"
|
|
559 elseif exists("b:is_kornshell")
|
|
560 let b:current_syntax = "ksh"
|
|
561 else
|
|
562 let b:current_syntax = "sh"
|
|
563 endif
|
|
564
|
22
|
565 " vim: ts=16 fdm=marker
|