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>
|
827
|
5 " Last Change: Apr 12, 2006
|
828
|
6 " Version: 84
|
507
|
7 " URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
|
7
|
8 "
|
22
|
9 " Using the following VIM variables: {{{1
|
828
|
10 " g:is_bash if none of the previous three variables are
|
|
11 " defined, then if g:is_bash is set enhance with
|
|
12 " bash syntax highlighting
|
557
|
13 " g:is_kornshell if neither b:is_kornshell or b:is_bash is
|
|
14 " defined, then if g:is_kornshell is set
|
|
15 " enhance with kornshell/POSIX syntax highlighting
|
828
|
16 " g:is_posix this variable is the same as g:is_kornshell
|
7
|
17 " g:sh_fold_enabled if non-zero, syntax folding is enabled
|
557
|
18 " g:sh_minlines sets up syn sync minlines (dflt: 200)
|
|
19 " g:sh_maxlines sets up syn sync maxlines (dflt: 2x sh_minlines)
|
7
|
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")
|
828
|
39 if exists("g:is_posix") && !exists("g:is_kornshell")
|
|
40 let g:is_kornshell= g:is_posix
|
|
41 endif
|
|
42 if exists("g:is_kornshell")
|
7
|
43 let b:is_kornshell= 1
|
|
44 if exists("b:is_sh")
|
|
45 unlet b:is_sh
|
|
46 endif
|
828
|
47 elseif exists("g:is_bash")
|
7
|
48 let b:is_bash= 1
|
|
49 if exists("b:is_sh")
|
|
50 unlet b:is_sh
|
|
51 endif
|
|
52 else
|
|
53 let b:is_sh= 1
|
|
54 endif
|
|
55 endif
|
|
56
|
199
|
57 " set up default g:sh_fold_enabled {{{1
|
7
|
58 if !exists("g:sh_fold_enabled")
|
|
59 let g:sh_fold_enabled= 0
|
36
|
60 elseif g:sh_fold_enabled != 0 && !has("folding")
|
|
61 let g:sh_fold_enabled= 0
|
199
|
62 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support"
|
|
63 endif
|
|
64 if g:sh_fold_enabled && &fdm == "manual"
|
|
65 set fdm=syntax
|
7
|
66 endif
|
|
67
|
199
|
68 " sh syntax is case sensitive {{{1
|
7
|
69 syn case match
|
|
70
|
22
|
71 " Clusters: contains=@... clusters {{{1
|
7
|
72 "==================================
|
167
|
73 syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shSpecial
|
199
|
74 syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shSpecial
|
7
|
75 syn cluster shColonList contains=@shCaseList
|
167
|
76 syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shNumber,shOperator,shPosnParm,shSpecial,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest
|
464
|
77 syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
|
7
|
78 syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shSpecial,shPosnParm
|
482
|
79 syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPPS
|
7
|
80 syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError
|
167
|
81 syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shSingleQuote,shDoubleQuote,shSpecial
|
|
82 syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shSingleQuote,shDoubleQuote,shSpecial,shExpr,shDblBrace,shDeref,shDerefSimple
|
119
|
83 syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest
|
820
|
84 syn cluster shFunctionList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shSpecial,shOperator,shFunctionStart
|
7
|
85 syn cluster shHereBeginList contains=@shCommandSubList
|
|
86 syn cluster shHereList contains=shBeginHere,shHerePayload
|
|
87 syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload
|
167
|
88 syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shIdWhiteSpace,shDeref,shDerefSimple,shSpecial,shRedir,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr
|
119
|
89 syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest
|
7
|
90 syn cluster shSubShList contains=@shCaseList
|
167
|
91 syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shDoubleQuote,shExpr,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shSpecial,shTestOpr,shTest
|
7
|
92
|
|
93
|
22
|
94 " Echo: {{{1
|
7
|
95 " ====
|
|
96 " This one is needed INSIDE a CommandSub, so that `echo bla` be correct
|
|
97 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
|
|
98 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
|
|
99
|
|
100 " This must be after the strings, so that bla \" be correct
|
167
|
101 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
|
102
|
22
|
103 " Alias: {{{1
|
7
|
104 " =====
|
|
105 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
106 syn match shStatement "\<alias\>"
|
|
107 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\w\+\)\@=" skip="\\$" end="\>\|`"
|
|
108 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\w\+=\)\@=" skip="\\$" end="="
|
|
109 endif
|
|
110
|
22
|
111 " Error Codes: {{{1
|
|
112 " ============
|
7
|
113 syn match shDoError "\<done\>"
|
|
114 syn match shIfError "\<fi\>"
|
|
115 syn match shInError "\<in\>"
|
|
116 syn match shCaseError ";;"
|
|
117 syn match shEsacError "\<esac\>"
|
|
118 syn match shCurlyError "}"
|
|
119 syn match shParenError ")"
|
|
120 if exists("b:is_kornshell")
|
|
121 syn match shDTestError "]]"
|
|
122 endif
|
|
123 syn match shTestError "]"
|
|
124
|
22
|
125 " Options Interceptor: {{{1
|
|
126 " ====================
|
7
|
127 syn match shOption "\s[\-+][a-zA-Z0-9]\+\>"ms=s+1
|
698
|
128 syn match shOption "\s--[^ \t$`'"|]\+"ms=s+1
|
7
|
129
|
22
|
130 " Operators: {{{1
|
|
131 " ==========
|
7
|
132 syn match shOperator "[!&;|]"
|
|
133 syn match shOperator "\[[[^:]\|\]]"
|
|
134 syn match shOperator "!\==" skipwhite nextgroup=shPattern
|
167
|
135 syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shDoubleQuote,shDeref
|
7
|
136
|
22
|
137 " Subshells: {{{1
|
|
138 " ==========
|
7
|
139 syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2
|
|
140 syn region shSubSh transparent matchgroup=shSubShRegion start="(" end=")" contains=@shSubShList
|
|
141
|
22
|
142 " Tests: {{{1
|
|
143 "=======
|
7
|
144 "syn region shExpr transparent matchgroup=shRange start="\[" skip=+\\\\\|\\$+ end="\]" contains=@shTestList
|
|
145 syn region shExpr matchgroup=shRange start="\[" skip=+\\\\\|\\$+ end="\]" contains=@shTestList
|
119
|
146 syn region shTest transparent matchgroup=shStatement start="\<test\>" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1
|
7
|
147 syn match shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!=<>]"
|
|
148 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
149 syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList
|
|
150 syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList
|
|
151 endif
|
|
152
|
22
|
153 " Character Class In Range: {{{1
|
|
154 " =========================
|
7
|
155 syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
|
|
156
|
22
|
157 " Loops: do, if, while, until {{{1
|
|
158 " ======
|
820
|
159 if g:sh_fold_enabled
|
|
160 syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
|
|
161 syn region shIf fold transparent matchgroup=shConditional start="\<if\>" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey
|
|
162 syn region shFor fold matchgroup=shLoop start="\<for\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
|
|
163 else
|
|
164 syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
|
|
165 syn region shIf transparent matchgroup=shConditional start="\<if\>" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey
|
|
166 syn region shFor matchgroup=shLoop start="\<for\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
|
|
167 endif
|
7
|
168 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
169 syn cluster shCaseList add=shRepeat
|
|
170 syn region shRepeat matchgroup=shLoop start="\<while\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
|
|
171 syn region shRepeat matchgroup=shLoop start="\<until\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
|
|
172 syn region shCaseEsac matchgroup=shConditional start="\<select\>" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
|
|
173 else
|
|
174 syn region shRepeat matchgroup=shLoop start="\<while\>" end="\<do\>"me=e-2 contains=@shLoopList
|
|
175 syn region shRepeat matchgroup=shLoop start="\<until\>" end="\<do\>"me=e-2 contains=@shLoopList
|
|
176 endif
|
464
|
177 syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList
|
|
178 syn match shComma contained ","
|
7
|
179
|
22
|
180 " Case: case...esac {{{1
|
7
|
181 " ====
|
167
|
182 syn match shCaseBar contained skipwhite "[^|"`'()]\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
|
7
|
183 syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar
|
659
|
184 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
|
820
|
185 if g:sh_fold_enabled
|
|
186 syn region shCaseEsac fold matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
|
|
187 else
|
|
188 syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
|
|
189 endif
|
167
|
190 syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
|
|
191 if exists("b:is_bash")
|
|
192 syn region shCaseExSingleQuote matchgroup=shOperator start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
193 else
|
|
194 syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
195 endif
|
659
|
196 syn region shCaseSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
7
|
197 syn region shCaseDoubleQuote matchgroup=shOperator start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
|
|
198 syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained
|
|
199
|
22
|
200 " Misc: {{{1
|
|
201 "======
|
7
|
202 syn match shWrapLineOperator "\\$"
|
|
203 syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
|
|
204
|
22
|
205 " $() and $(()): {{{1
|
7
|
206 " $(..) is not supported by sh (Bourne shell). However, apparently
|
|
207 " some systems (HP?) have as their /bin/sh a (link to) Korn shell
|
|
208 " (ie. Posix compliant shell). /bin/ksh should work for those
|
|
209 " systems too, however, so the following syntax will flag $(..) as
|
|
210 " an Error under /bin/sh. By consensus of vimdev'ers!
|
|
211 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
212 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
|
|
213 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shCommandSubList
|
|
214 syn match shSkipInitWS contained "^\s\+"
|
|
215 else
|
167
|
216 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
|
7
|
217 endif
|
|
218
|
|
219 if exists("b:is_bash")
|
|
220 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
|
|
221 syn cluster shCaseList add=bashAdminStatement,bashStatement
|
|
222 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
|
|
223 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
|
|
224 syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop
|
|
225 endif
|
|
226
|
|
227 if exists("b:is_kornshell")
|
|
228 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
|
|
229 syn cluster shCaseList add=kshStatement
|
|
230 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
|
|
231 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
|
|
232 endif
|
|
233
|
|
234 syn match shSource "^\.\s"
|
|
235 syn match shSource "\s\.\s"
|
|
236 syn region shColon start="^\s*:" end="$\|" end="#"me=e-1 contains=@shColonList
|
|
237
|
22
|
238 " String And Character Constants: {{{1
|
|
239 "================================
|
7
|
240 syn match shNumber "-\=\<\d\+\>"
|
167
|
241 if exists("b:is_bash")
|
|
242 syn match shSpecial "\\\o\o\o\|\\x\x\x\|\\c.\|\\[abefnrtv]" contained
|
|
243 else
|
|
244 syn match shSpecial "\\\d\d\d\|\\[abcfnrtv0]" contained
|
|
245 endif
|
|
246 if exists("b:is_bash")
|
|
247 syn region shExSingleQuote matchgroup=shOperator start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
|
|
248 else
|
|
249 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
|
|
250 endif
|
7
|
251 syn region shSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial
|
|
252 syn region shDoubleQuote matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
|
|
253 syn match shStringSpecial "[^[:print:]]" contained
|
|
254 syn match shSpecial "\\[\\\"\'`$()#]"
|
|
255
|
22
|
256 " Comments: {{{1
|
|
257 "==========
|
7
|
258 syn cluster shCommentGroup contains=shTodo,@Spell
|
827
|
259 syn keyword shTodo contained COMBAK FIXME TODO XXX
|
7
|
260 syn match shComment "#.*$" contains=@shCommentGroup
|
|
261
|
22
|
262 " File Redirection Highlighted As Operators: {{{1
|
|
263 "===========================================
|
7
|
264 syn match shRedir "\d\=>\(&[-0-9]\)\="
|
|
265 syn match shRedir "\d\=>>-\="
|
|
266 syn match shRedir "\d\=<\(&[-0-9]\)\="
|
|
267 syn match shRedir "\d<<-\="
|
|
268
|
22
|
269 " Here Documents: {{{1
|
|
270 " =========================================
|
7
|
271 if version < 600
|
|
272 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
|
|
273 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
|
|
274 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
|
|
275 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
|
|
276 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
|
|
277 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
|
|
278
|
|
279 elseif g:sh_fold_enabled
|
199
|
280 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
|
|
281 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
|
|
282 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
|
|
283 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
|
|
284 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
285 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
286 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
|
|
287 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
|
|
288 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
289 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
290 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
291 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
|
7
|
292
|
|
293 else
|
199
|
294 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\=\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
|
|
295 syn region shHereDoc matchgroup=shRedir start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
|
|
296 syn region shHereDoc matchgroup=shRedir start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
|
|
297 syn region shHereDoc matchgroup=shRedir start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
298 syn region shHereDoc matchgroup=shRedir start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
|
|
299 syn region shHereDoc matchgroup=shRedir start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
300 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
|
|
301 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
302 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
|
|
303 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
|
|
304 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
|
|
305 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
|
7
|
306 endif
|
|
307
|
22
|
308 " Here Strings: {{{1
|
|
309 " =============
|
|
310 if exists("b:is_bash")
|
|
311 syn match shRedir "<<<"
|
|
312 endif
|
|
313
|
|
314 " Identifiers: {{{1
|
|
315 "=============
|
7
|
316 syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier
|
|
317 syn match shIdWhiteSpace contained "\s"
|
167
|
318 syn match shSetIdentifier contained "=" nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shSingleQuote,shExSingleQuote
|
7
|
319 if exists("b:is_bash")
|
119
|
320 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
|
|
321 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
|
322 syn match shSet "\<\(declare\|typeset\|local\|export\|set\|unset\)$"
|
|
323 elseif exists("b:is_kornshell")
|
119
|
324 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
|
|
325 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
|
326 syn match shSet "\<\(typeset\|set\|export\|unset\)$"
|
|
327 else
|
119
|
328 syn region shSetList matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$\|\ze[|)]" matchgroup=shOperator end="[;&]" matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
|
7
|
329 syn match shStatement "\<\(set\|export\|unset\)$"
|
|
330 endif
|
|
331
|
22
|
332 " Functions: {{{1
|
199
|
333 syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo
|
820
|
334 syn match shFunctionStart "^\s*{" contained
|
7
|
335 if g:sh_fold_enabled
|
199
|
336 syn region shFunctionOne transparent fold start="^\s*\h\w*\s*()\_s*\ze{" matchgroup=shFunctionStart end="}" contains=@shFunctionList
|
|
337 syn region shFunctionTwo transparent fold start="\h\w*\s*\%(()\)\=\_s*\ze{" matchgroup=shFunctionStart end="}" contains=shFunctionKey,@shFunctionList contained
|
7
|
338 else
|
199
|
339 syn region shFunctionOne transparent start="^\s*\h\w*\s*()\_s*\ze{" matchgroup=shFunctionStart end="}" contains=@shFunctionList
|
|
340 syn region shFunctionTwo transparent start="\h\w*\s*\%(()\)\=\_s*\ze{" matchgroup=shFunctionStart end="}" contains=shFunctionKey,@shFunctionList contained
|
7
|
341 endif
|
|
342
|
22
|
343 " Parameter Dereferencing: {{{1
|
|
344 " ========================
|
36
|
345 syn match shDerefSimple "\$\%(\h\w*\|\d\)"
|
7
|
346 syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray
|
|
347 syn match shDerefWordError "[^}$[]" contained
|
|
348 syn match shDerefSimple "\$[-#*@!?]"
|
|
349 syn match shDerefSimple "\$\$"
|
|
350 if exists("b:is_bash") || exists("b:is_kornshell")
|
|
351 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
|
|
352 endif
|
|
353
|
22
|
354 " bash: ${!prefix*} and ${#parameter}: {{{1
|
|
355 " ====================================
|
7
|
356 if exists("b:is_bash")
|
|
357 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp
|
|
358 syn match shDerefVar contained "{\@<=!\w\+" nextgroup=@shDerefVarList
|
|
359 endif
|
|
360
|
|
361 syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError
|
|
362 syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp
|
|
363 syn match shDerefVar contained "{\@<=\w\+" nextgroup=@shDerefVarList
|
|
364
|
22
|
365 " sh ksh bash : ${var[... ]...} array reference: {{{1
|
7
|
366 syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError
|
|
367
|
22
|
368 " Special ${parameter OPERATOR word} handling: {{{1
|
7
|
369 " sh ksh bash : ${parameter:-word} word is default value
|
|
370 " sh ksh bash : ${parameter:=word} assign word as default value
|
|
371 " sh ksh bash : ${parameter:?word} display word if parameter is null
|
|
372 " sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing
|
|
373 " ksh bash : ${parameter#pattern} remove small left pattern
|
|
374 " ksh bash : ${parameter##pattern} remove large left pattern
|
|
375 " ksh bash : ${parameter%pattern} remove small right pattern
|
|
376 " ksh bash : ${parameter%%pattern} remove large right pattern
|
|
377 syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
|
|
378 syn match shDerefOpError contained ":[[:punct:]]"
|
|
379 syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList
|
|
380 syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList
|
|
381 if exists("b:is_bash") || exists("b:is_kornshell")
|
|
382 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList
|
|
383 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
|
482
|
384 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern
|
7
|
385 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
|
482
|
386 syn match shDerefEscape contained '\%(\\\\\)*\\.'
|
7
|
387 endif
|
|
388 syn region shDerefString contained matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial
|
|
389 syn region shDerefString contained matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
|
|
390 syn match shDerefString contained "\\["']"
|
|
391
|
|
392 if exists("b:is_bash")
|
482
|
393 " bash : ${parameter:offset}
|
|
394 " bash : ${parameter:offset:length}
|
7
|
395 syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL
|
482
|
396 syn match shDerefPOL contained ":[^}]\+" contains=@shCommandSubList
|
|
397
|
|
398 " bash : ${parameter//pattern/string}
|
|
399 " bash : ${parameter//pattern}
|
|
400 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft
|
557
|
401 syn region shDerefPPSleft contained start='.' skip=@\%(\\\)\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList
|
482
|
402 syn region shDerefPPSright contained start='.' end='\ze}' contains=@shCommandSubList
|
7
|
403 endif
|
|
404
|
22
|
405 " Useful sh Keywords: {{{1
|
|
406 " ===================
|
7
|
407 syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
|
|
408 syn keyword shConditional contained elif else then
|
|
409 syn keyword shCondError elif else then
|
|
410
|
22
|
411 " Useful ksh Keywords: {{{1
|
|
412 " ====================
|
7
|
413 if exists("b:is_kornshell") || exists("b:is_bash")
|
|
414 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
|
|
415
|
22
|
416 " Useful bash Keywords: {{{1
|
|
417 " =====================
|
7
|
418 if exists("b:is_bash")
|
|
419 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
|
|
420 else
|
|
421 syn keyword shStatement login newgrp
|
|
422 endif
|
|
423 endif
|
|
424
|
22
|
425 " Synchronization: {{{1
|
|
426 " ================
|
7
|
427 if !exists("sh_minlines")
|
|
428 let sh_minlines = 200
|
|
429 endif
|
|
430 if !exists("sh_maxlines")
|
|
431 let sh_maxlines = 2 * sh_minlines
|
|
432 endif
|
|
433 exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
|
|
434 syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
|
|
435 syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
|
|
436 syn sync match shDoSync grouphere shDo "\<do\>"
|
|
437 syn sync match shDoSync groupthere shDo "\<done\>"
|
|
438 syn sync match shForSync grouphere shFor "\<for\>"
|
|
439 syn sync match shForSync groupthere shFor "\<in\>"
|
|
440 syn sync match shIfSync grouphere shIf "\<if\>"
|
|
441 syn sync match shIfSync groupthere shIf "\<fi\>"
|
|
442 syn sync match shUntilSync grouphere shRepeat "\<until\>"
|
|
443 syn sync match shWhileSync grouphere shRepeat "\<while\>"
|
|
444
|
22
|
445 " Default Highlighting: {{{1
|
|
446 " =====================
|
7
|
447 hi def link shArithRegion shShellVariables
|
167
|
448 hi def link shBeginHere shRedir
|
7
|
449 hi def link shCaseBar shConditional
|
|
450 hi def link shCaseCommandSub shCommandSub
|
|
451 hi def link shCaseDoubleQuote shDoubleQuote
|
167
|
452 hi def link shCaseIn shConditional
|
7
|
453 hi def link shCaseSingleQuote shSingleQuote
|
|
454 hi def link shCaseStart shConditional
|
|
455 hi def link shCmdSubRegion shShellVariables
|
|
456 hi def link shColon shStatement
|
167
|
457 hi def link shDerefOp shOperator
|
|
458 hi def link shDerefPOL shDerefOp
|
482
|
459 hi def link shDerefPPS shDerefOp
|
7
|
460 hi def link shDeref shShellVariables
|
|
461 hi def link shDerefSimple shDeref
|
|
462 hi def link shDerefSpecial shDeref
|
|
463 hi def link shDerefString shDoubleQuote
|
167
|
464 hi def link shDerefVar shDeref
|
7
|
465 hi def link shDoubleQuote shString
|
|
466 hi def link shEcho shString
|
|
467 hi def link shEmbeddedEcho shString
|
167
|
468 hi def link shExSingleQuote shSingleQuote
|
199
|
469 hi def link shFunctionStart Delimiter
|
7
|
470 hi def link shHereDoc shString
|
167
|
471 hi def link shHerePayload shHereDoc
|
7
|
472 hi def link shLoop shStatement
|
|
473 hi def link shOption shCommandSub
|
|
474 hi def link shPattern shString
|
|
475 hi def link shPosnParm shShellVariables
|
|
476 hi def link shRange shOperator
|
|
477 hi def link shRedir shOperator
|
|
478 hi def link shSingleQuote shString
|
|
479 hi def link shSource shOperator
|
|
480 hi def link shStringSpecial shSpecial
|
|
481 hi def link shSubShRegion shOperator
|
|
482 hi def link shTestOpr shConditional
|
|
483 hi def link shVariable shSetList
|
|
484 hi def link shWrapLineOperator shOperator
|
|
485
|
|
486 if exists("b:is_bash")
|
|
487 hi def link bashAdminStatement shStatement
|
|
488 hi def link bashSpecialVariables shShellVariables
|
|
489 hi def link bashStatement shStatement
|
199
|
490 hi def link shFunctionParen Delimiter
|
|
491 hi def link shFunctionDelim Delimiter
|
7
|
492 endif
|
|
493 if exists("b:is_kornshell")
|
|
494 hi def link kshSpecialVariables shShellVariables
|
|
495 hi def link kshStatement shStatement
|
199
|
496 hi def link shFunctionParen Delimiter
|
7
|
497 endif
|
|
498
|
|
499 hi def link shCaseError Error
|
|
500 hi def link shCondError Error
|
|
501 hi def link shCurlyError Error
|
|
502 hi def link shDerefError Error
|
|
503 hi def link shDerefOpError Error
|
|
504 hi def link shDerefWordError Error
|
|
505 hi def link shDoError Error
|
|
506 hi def link shEsacError Error
|
|
507 hi def link shIfError Error
|
|
508 hi def link shInError Error
|
|
509 hi def link shParenError Error
|
|
510 hi def link shTestError Error
|
|
511 if exists("b:is_kornshell")
|
|
512 hi def link shDTestError Error
|
|
513 endif
|
|
514
|
|
515 hi def link shArithmetic Special
|
|
516 hi def link shCharClass Identifier
|
|
517 hi def link shSnglCase Statement
|
|
518 hi def link shCommandSub Special
|
|
519 hi def link shComment Comment
|
|
520 hi def link shConditional Conditional
|
|
521 hi def link shExprRegion Delimiter
|
199
|
522 hi def link shFunctionKey Function
|
7
|
523 hi def link shFunctionName Function
|
|
524 hi def link shNumber Number
|
|
525 hi def link shOperator Operator
|
|
526 hi def link shRepeat Repeat
|
|
527 hi def link shSet Statement
|
|
528 hi def link shSetList Identifier
|
|
529 hi def link shShellVariables PreProc
|
|
530 hi def link shSpecial Special
|
|
531 hi def link shStatement Statement
|
|
532 hi def link shString String
|
|
533 hi def link shTodo Todo
|
|
534 hi def link shAlias Identifier
|
|
535
|
22
|
536 " Set Current Syntax: {{{1
|
|
537 " ===================
|
7
|
538 if exists("b:is_bash")
|
|
539 let b:current_syntax = "bash"
|
|
540 elseif exists("b:is_kornshell")
|
|
541 let b:current_syntax = "ksh"
|
|
542 else
|
|
543 let b:current_syntax = "sh"
|
|
544 endif
|
|
545
|
22
|
546 " vim: ts=16 fdm=marker
|