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