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>
|
119
|
5 " Last Change: Dec 28, 2004
|
|
6 " Version: 71
|
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 "==================================
|
|
66 syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseSingleQuote,shCaseDoubleQuote,shSpecial
|
|
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
|
119
|
69 syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shNumber,shOperator,shPosnParm,shSpecial,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
|
|
73 syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shSingleQuote,shDoubleQuote,shSpecial
|
|
74 syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,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
|
|
80 syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shIdWhiteSpace,shDeref,shDerefSimple,shSpecial,shRedir,shSingleQuote,shDoubleQuote,shExpr
|
119
|
81 syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest
|
7
|
82 syn cluster shSubShList contains=@shCaseList
|
119
|
83 syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shDoubleQuote,shExpr,shExpr,shNumber,shOperator,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
|
|
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,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shSpecial,shOperator,shDoubleQuote,shCharClass
|
|
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
|
|
127 syn match shPattern "\<\S\+\())\)\@=" contained contains=shSingleQuote,shDoubleQuote,shDeref
|
|
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 " ====
|
|
166 syn match shCaseBar contained skipwhite "[^|"`'()]\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseSingleQuote,shCaseDoubleQuote
|
|
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
|
|
170 syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseSingleQuote,shCaseDoubleQuote
|
|
171 syn region shCaseSingleQuote matchgroup=shOperator start=+'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
172 syn region shCaseDoubleQuote matchgroup=shOperator start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
173 syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained
|
|
174
|
22
|
175 " Misc: {{{1
|
|
176 "======
|
7
|
177 syn match shWrapLineOperator "\\$"
|
|
178 syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
|
|
179
|
22
|
180 " $() and $(()): {{{1
|
7
|
181 " $(..) is not supported by sh (Bourne shell). However, apparently
|
|
182 " some systems (HP?) have as their /bin/sh a (link to) Korn shell
|
|
183 " (ie. Posix compliant shell). /bin/ksh should work for those
|
|
184 " systems too, however, so the following syntax will flag $(..) as
|
|
185 " an Error under /bin/sh. By consensus of vimdev'ers!
|
|
186 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
187 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
|
|
188 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shCommandSubList
|
|
189 syn match shSkipInitWS contained "^\s\+"
|
|
190 else
|
|
191 syn region shCommandSub matchgroup=Error start="$(" end=")" contains=@shCommandSubList
|
|
192 endif
|
|
193
|
|
194 if exists("b:is_bash")
|
|
195 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
|
|
196 syn cluster shCaseList add=bashAdminStatement,bashStatement
|
|
197 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
|
|
198 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
|
|
199 syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop
|
|
200 endif
|
|
201
|
|
202 if exists("b:is_kornshell")
|
|
203 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
|
|
204 syn cluster shCaseList add=kshStatement
|
|
205 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
|
|
206 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
|
|
207 endif
|
|
208
|
|
209 syn match shSource "^\.\s"
|
|
210 syn match shSource "\s\.\s"
|
|
211 syn region shColon start="^\s*:" end="$\|" end="#"me=e-1 contains=@shColonList
|
|
212
|
22
|
213 " String And Character Constants: {{{1
|
|
214 "================================
|
7
|
215 syn match shNumber "-\=\<\d\+\>"
|
|
216 syn match shSpecial "\\\d\d\d\|\\[abcfnrtv0]" contained
|
|
217 syn region shSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial
|
|
218 syn region shDoubleQuote matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
|
|
219 syn match shStringSpecial "[^[:print:]]" contained
|
|
220 syn match shSpecial "\\[\\\"\'`$()#]"
|
|
221
|
22
|
222 " Comments: {{{1
|
|
223 "==========
|
7
|
224 syn cluster shCommentGroup contains=shTodo,@Spell
|
|
225 syn keyword shTodo contained TODO
|
|
226 syn match shComment "#.*$" contains=@shCommentGroup
|
|
227
|
22
|
228 " File Redirection Highlighted As Operators: {{{1
|
|
229 "===========================================
|
7
|
230 syn match shRedir "\d\=>\(&[-0-9]\)\="
|
|
231 syn match shRedir "\d\=>>-\="
|
|
232 syn match shRedir "\d\=<\(&[-0-9]\)\="
|
|
233 syn match shRedir "\d<<-\="
|
|
234
|
22
|
235 " Here Documents: {{{1
|
|
236 " =========================================
|
7
|
237 if version < 600
|
|
238 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
|
|
239 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
|
|
240 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
|
|
241 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
|
|
242 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
|
|
243 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
|
|
244
|
|
245 elseif g:sh_fold_enabled
|
|
246
|
|
247 if v:version > 602 || (v:version == 602 && has("patch219"))
|
|
248 syn region shHereDoc fold start="\(<<\s*\\\=\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereListDQ keepend
|
|
249 syn region shHereDoc fold start="\(<<\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
250 syn region shHereDoc fold start="\(<<\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
251 syn region shHereDoc fold start="\(<<\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
252 syn region shHereDoc fold start="\(<<\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
253 syn region shHereDoc fold start="\(<<\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereList keepend
|
|
254 syn region shHereDoc fold start="\(<<-\s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
255 syn region shHereDoc fold start="\(<<-\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereListDQ keepend
|
|
256 syn region shHereDoc fold start="\(<<-\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereList keepend
|
|
257 syn region shHereDoc fold start="\(<<-\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
258 syn region shHereDoc fold start="\(<<-\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
259 syn region shHereDoc fold start="\(<<-\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
260 else
|
|
261 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z(\S*\)" matchgroup=shRedir end="^\z1$" contains=@shDblQuoteList
|
|
262 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
263 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
264 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$" contains=@shDblQuoteList
|
|
265 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
266 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
267 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1$"
|
|
268 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
269 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
270 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$"
|
|
271 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
272 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
273 endif
|
|
274 else
|
|
275 if v:version > 602 || (v:version == 602 && has("patch219"))
|
|
276 syn region shHereDoc start="\(<<\s*\\\=\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereList keepend
|
|
277 syn region shHereDoc start="\(<<\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereListDQ keepend
|
|
278 syn region shHereDoc start="\(<<\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
279 syn region shHereDoc start="\(<<\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
280 syn region shHereDoc start="\(<<\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\z1$"" contains=@shHereList keepend
|
|
281 syn region shHereDoc start="\(<<\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\z1$" contains=@shHereList keepend
|
|
282 syn region shHereDoc start="\(<<-\s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
283 syn region shHereDoc start="\(<<-\s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereListDQ keepend
|
|
284 syn region shHereDoc start="\(<<-\s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$"" contains=@shHereList keepend
|
|
285 syn region shHereDoc start="\(<<-\s*\\\_$\_s*'\z(\S*\)'\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
286 syn region shHereDoc start="\(<<-\s*\\\_$\_s*\z(\S*\)\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
|
287 syn region shHereDoc start="\(<<-\s*\\\_$\_s*\"\z(\S*\)\"\)\@=" matchgroup=shRedir end="^\s*\z1$" contains=@shHereList keepend
|
119
|
288 syn match shHerePayload "^.*$" contained skipnl nextgroup=shHerePayload contains=@shDblQuoteList
|
|
289 syn match shBeginLine ".*$" contained skipnl nextgroup=shHerePayload contains=@shCommandSubList
|
|
290 syn match shBeginHere "<<-\=\s*\S\+" contained nextgroup=shBeginLine
|
7
|
291 else
|
|
292 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\=\z(\S*\)" matchgroup=shRedir end="^\z1$" contains=@shDblQuoteList
|
|
293 syn region shHereDoc matchgroup=shRedir start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
294 syn region shHereDoc matchgroup=shRedir start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$" contains=@shDblQuoteList
|
|
295 syn region shHereDoc matchgroup=shRedir start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
296 syn region shHereDoc matchgroup=shRedir start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
297 syn region shHereDoc matchgroup=shRedir start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
298 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1$"
|
|
299 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1$"
|
|
300 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1$"
|
|
301 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1$"
|
|
302 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1$"
|
|
303 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1$"
|
|
304 endif
|
|
305 endif
|
|
306
|
22
|
307 " Here Strings: {{{1
|
|
308 " =============
|
|
309 if exists("b:is_bash")
|
|
310 syn match shRedir "<<<"
|
|
311 endif
|
|
312
|
|
313 " Identifiers: {{{1
|
|
314 "=============
|
7
|
315 syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier
|
|
316 syn match shIdWhiteSpace contained "\s"
|
|
317 syn match shSetIdentifier contained "=" nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shSingleQuote
|
|
318 if exists("b:is_bash")
|
119
|
319 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
|
|
320 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
|
321 syn match shSet "\<\(declare\|typeset\|local\|export\|set\|unset\)$"
|
|
322 elseif exists("b:is_kornshell")
|
119
|
323 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
|
|
324 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
|
325 syn match shSet "\<\(typeset\|set\|export\|unset\)$"
|
|
326 else
|
119
|
327 syn region shSetList matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$\|\ze[|)]" matchgroup=shOperator end="[;&]" matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
|
7
|
328 syn match shStatement "\<\(set\|export\|unset\)$"
|
|
329 endif
|
|
330
|
22
|
331 " Functions: {{{1
|
7
|
332 " handles functions which start: Function () {
|
|
333 " Apparently Bourne shell accepts functions too,
|
|
334 " even though it isn't documented by my man pages
|
|
335 " for it.
|
|
336 syn cluster shCommandSubList add=bkshFunction
|
|
337 if g:sh_fold_enabled
|
|
338 syn region bkshFunctionBody transparent fold matchgroup=Delimiter start="^\s*\<\h\w*\>\s*()\s*{" end="}" contains=bkshFunction,bkshFunctionDelim,@shFunctionList
|
|
339 else
|
|
340 syn region bkshFunctionBody transparent matchgroup=Delimiter start="^\s*\<\h\w*\>\s*()\s*{" end="}" contains=bkshFunction,bkshFunctionDelim,@shFunctionList
|
|
341 endif
|
|
342 syn match bkshFunction "^\s*\<\h\w*\>\s*()" skipwhite skipnl contains=bkshFunctionParen
|
|
343 syn match bkshFunctionParen "[()]" contained
|
|
344 syn match bkshFunctionDelim "[{}]" contained
|
|
345
|
22
|
346 " Parameter Dereferencing: {{{1
|
|
347 " ========================
|
36
|
348 syn match shDerefSimple "\$\%(\h\w*\|\d\)"
|
7
|
349 syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray
|
|
350 syn match shDerefWordError "[^}$[]" contained
|
|
351 syn match shDerefSimple "\$[-#*@!?]"
|
|
352 syn match shDerefSimple "\$\$"
|
|
353 if exists("b:is_bash") || exists("b:is_kornshell")
|
|
354 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
|
|
355 endif
|
|
356
|
22
|
357 " bash: ${!prefix*} and ${#parameter}: {{{1
|
|
358 " ====================================
|
7
|
359 if exists("b:is_bash")
|
|
360 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp
|
|
361 syn match shDerefVar contained "{\@<=!\w\+" nextgroup=@shDerefVarList
|
|
362 endif
|
|
363
|
|
364 syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError
|
|
365 syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp
|
|
366 syn match shDerefVar contained "{\@<=\w\+" nextgroup=@shDerefVarList
|
|
367
|
22
|
368 " sh ksh bash : ${var[... ]...} array reference: {{{1
|
7
|
369 syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError
|
|
370
|
22
|
371 " Special ${parameter OPERATOR word} handling: {{{1
|
7
|
372 " sh ksh bash : ${parameter:-word} word is default value
|
|
373 " sh ksh bash : ${parameter:=word} assign word as default value
|
|
374 " sh ksh bash : ${parameter:?word} display word if parameter is null
|
|
375 " sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing
|
|
376 " ksh bash : ${parameter#pattern} remove small left pattern
|
|
377 " ksh bash : ${parameter##pattern} remove large left pattern
|
|
378 " ksh bash : ${parameter%pattern} remove small right pattern
|
|
379 " ksh bash : ${parameter%%pattern} remove large right pattern
|
|
380 syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
|
|
381 syn match shDerefOpError contained ":[[:punct:]]"
|
|
382 syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList
|
|
383 syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList
|
|
384 if exists("b:is_bash") || exists("b:is_kornshell")
|
|
385 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList
|
|
386 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
|
|
387 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub nextgroup=shDerefPattern
|
|
388 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
|
|
389 endif
|
|
390 syn region shDerefString contained matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial
|
|
391 syn region shDerefString contained matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
|
|
392 syn match shDerefString contained "\\["']"
|
|
393
|
|
394 " bash : ${parameter:offset}
|
|
395 " bash : ${parameter:offset:length}
|
|
396 " bash : ${parameter//pattern/string}
|
|
397 " bash : ${parameter//pattern}
|
|
398 if exists("b:is_bash")
|
|
399 syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL
|
|
400 syn match shDerefPOL contained ":[^}]\{1,}" contains=@shCommandSubList
|
|
401 syn match shDerefOp contained "/\{1,2}" nextgroup=shDerefPat
|
|
402 syn match shDerefPat contained "[^/}]\{1,}" nextgroup=shDerefPatStringOp
|
|
403 syn match shDerefPatStringOp contained "/" nextgroup=shDerefPatString
|
|
404 syn match shDerefPatString contained "[^}]\{1,}"
|
|
405 endif
|
|
406
|
22
|
407 " Useful sh Keywords: {{{1
|
|
408 " ===================
|
7
|
409 syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
|
|
410 syn keyword shConditional contained elif else then
|
|
411 syn keyword shCondError elif else then
|
|
412
|
22
|
413 " Useful ksh Keywords: {{{1
|
|
414 " ====================
|
7
|
415 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
416 syn keyword shFunction function
|
|
417 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
|
|
418
|
22
|
419 " Useful bash Keywords: {{{1
|
|
420 " =====================
|
7
|
421 if exists("b:is_bash")
|
|
422 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
|
|
423 else
|
|
424 syn keyword shStatement login newgrp
|
|
425 endif
|
|
426 endif
|
|
427
|
22
|
428 " Synchronization: {{{1
|
|
429 " ================
|
7
|
430 if !exists("sh_minlines")
|
|
431 let sh_minlines = 200
|
|
432 endif
|
|
433 if !exists("sh_maxlines")
|
|
434 let sh_maxlines = 2 * sh_minlines
|
|
435 endif
|
|
436 exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
|
|
437 syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
|
|
438 syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
|
|
439 syn sync match shDoSync grouphere shDo "\<do\>"
|
|
440 syn sync match shDoSync groupthere shDo "\<done\>"
|
|
441 syn sync match shForSync grouphere shFor "\<for\>"
|
|
442 syn sync match shForSync groupthere shFor "\<in\>"
|
|
443 syn sync match shIfSync grouphere shIf "\<if\>"
|
|
444 syn sync match shIfSync groupthere shIf "\<fi\>"
|
|
445 syn sync match shUntilSync grouphere shRepeat "\<until\>"
|
|
446 syn sync match shWhileSync grouphere shRepeat "\<while\>"
|
|
447
|
22
|
448 " Default Highlighting: {{{1
|
|
449 " =====================
|
7
|
450 hi def link shArithRegion shShellVariables
|
|
451 hi def link shCaseBar shConditional
|
|
452 hi def link shCaseIn shConditional
|
|
453 hi def link shCaseCommandSub shCommandSub
|
|
454 hi def link shCaseDoubleQuote shDoubleQuote
|
|
455 hi def link shCaseSingleQuote shSingleQuote
|
|
456 hi def link shCaseStart shConditional
|
|
457 hi def link shCmdSubRegion shShellVariables
|
|
458 hi def link shColon shStatement
|
|
459
|
|
460 hi def link shDeref shShellVariables
|
|
461 hi def link shDerefOp shOperator
|
|
462
|
|
463 hi def link shDerefVar shDeref
|
|
464 hi def link shDerefPOL shDerefOp
|
|
465 hi def link shDerefPatString shDerefPattern
|
|
466 hi def link shDerefPatStringOp shDerefOp
|
|
467 hi def link shDerefSimple shDeref
|
|
468 hi def link shDerefSpecial shDeref
|
|
469 hi def link shDerefString shDoubleQuote
|
|
470 hi def link shHerePayload shHereDoc
|
|
471 hi def link shBeginHere shRedir
|
|
472
|
|
473 hi def link shDoubleQuote shString
|
|
474 hi def link shEcho shString
|
|
475 hi def link shEmbeddedEcho shString
|
|
476 hi def link shHereDoc shString
|
|
477 hi def link shLoop shStatement
|
|
478 hi def link shOption shCommandSub
|
|
479 hi def link shPattern shString
|
|
480 hi def link shPosnParm shShellVariables
|
|
481 hi def link shRange shOperator
|
|
482 hi def link shRedir shOperator
|
|
483 hi def link shSingleQuote shString
|
|
484 hi def link shSource shOperator
|
|
485 hi def link shStringSpecial shSpecial
|
|
486 hi def link shSubShRegion shOperator
|
|
487 hi def link shTestOpr shConditional
|
|
488 hi def link shVariable shSetList
|
|
489 hi def link shWrapLineOperator shOperator
|
|
490
|
|
491 if exists("b:is_bash")
|
|
492 hi def link bashAdminStatement shStatement
|
|
493 hi def link bashSpecialVariables shShellVariables
|
|
494 hi def link bashStatement shStatement
|
|
495 hi def link bkshFunction Function
|
|
496 hi def link bkshFunctionParen Delimiter
|
|
497 hi def link bkshFunctionDelim Delimiter
|
|
498 endif
|
|
499 if exists("b:is_kornshell")
|
|
500 hi def link kshSpecialVariables shShellVariables
|
|
501 hi def link kshStatement shStatement
|
|
502 hi def link bkshFunction Function
|
|
503 hi def link bkshFunctionParen Delimiter
|
|
504 endif
|
|
505
|
|
506 hi def link shCaseError Error
|
|
507 hi def link shCondError Error
|
|
508 hi def link shCurlyError Error
|
|
509 hi def link shDerefError Error
|
|
510 hi def link shDerefOpError Error
|
|
511 hi def link shDerefWordError Error
|
|
512 hi def link shDoError Error
|
|
513 hi def link shEsacError Error
|
|
514 hi def link shIfError Error
|
|
515 hi def link shInError Error
|
|
516 hi def link shParenError Error
|
|
517 hi def link shTestError Error
|
|
518 if exists("b:is_kornshell")
|
|
519 hi def link shDTestError Error
|
|
520 endif
|
|
521
|
|
522 hi def link shArithmetic Special
|
|
523 hi def link shCharClass Identifier
|
|
524 hi def link shSnglCase Statement
|
|
525 hi def link shCommandSub Special
|
|
526 hi def link shComment Comment
|
|
527 hi def link shConditional Conditional
|
|
528 hi def link shExprRegion Delimiter
|
|
529 hi def link shFunction Function
|
|
530 hi def link shFunctionName Function
|
|
531 hi def link shNumber Number
|
|
532 hi def link shOperator Operator
|
|
533 hi def link shRepeat Repeat
|
|
534 hi def link shSet Statement
|
|
535 hi def link shSetList Identifier
|
|
536 hi def link shShellVariables PreProc
|
|
537 hi def link shSpecial Special
|
|
538 hi def link shStatement Statement
|
|
539 hi def link shString String
|
|
540 hi def link shTodo Todo
|
|
541 hi def link shAlias Identifier
|
|
542
|
22
|
543 " Set Current Syntax: {{{1
|
|
544 " ===================
|
7
|
545 if exists("b:is_bash")
|
|
546 let b:current_syntax = "bash"
|
|
547 elseif exists("b:is_kornshell")
|
|
548 let b:current_syntax = "ksh"
|
|
549 else
|
|
550 let b:current_syntax = "sh"
|
|
551 endif
|
|
552
|
22
|
553 " vim: ts=16 fdm=marker
|