Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: shell (sh) Korn shell (ksh) bash (sh) |
Christian Brabandt | f9ca139 | 2024-02-19 20:37:11 +0100 | [diff] [blame] | 3 | " Maintainer: This runtime file is looking for a new maintainer. |
| 4 | " Previous Maintainers: Charles E. Campbell |
| 5 | " Lennart Schultz <Lennart.Schultz@ecmwf.int> |
dkearns | 1bdc943 | 2024-03-05 05:14:08 +1100 | [diff] [blame] | 6 | " Last Change: 2024 Mar 04 by Vim Project |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 7 | " 2024 Nov 03 by Aliaksei Budavei <0x000c70 AT gmail DOT com> (improved bracket expressions, #15941) |
Christian Brabandt | 3159b64 | 2025-01-06 18:50:15 +0100 | [diff] [blame] | 8 | " 2025 Jan 06 add $PS0 to bashSpecialVariables (#16394) |
Eisuke Kawashima | 54cb514 | 2025-01-18 10:11:28 +0100 | [diff] [blame] | 9 | " 2025 Jan 18 add bash coproc, remove duplicate syn keywords (#16467) |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 10 | " 2025 Mar 21 update shell capability detection (#16939) |
Doug Kearns | 6099db9 | 2025-04-03 21:13:39 +0200 | [diff] [blame] | 11 | " 2025 Apr 03 command substitution opening paren at EOL (#17026) |
Aliaksei Budavei | 5c84d12 | 2025-04-10 21:52:14 +0200 | [diff] [blame] | 12 | " 2025 Apr 10 improve shell detection (#17084) |
Doug Kearns | f57c065 | 2025-04-30 20:04:28 +0200 | [diff] [blame] | 13 | " 2025 Apr 29 match escaped chars in test operands (#17221) |
Doug Kearns | fe22867 | 2025-05-05 20:10:11 +0200 | [diff] [blame] | 14 | " 2025 May 06 improve single-quote string matching in parameter expansions |
Doug Kearns | 87947a9 | 2025-05-06 17:59:25 +0200 | [diff] [blame] | 15 | " 2025 May 06 match KornShell compound arrays |
Doug Kearns | 839b79e | 2025-05-10 20:57:10 +0200 | [diff] [blame] | 16 | " 2025 May 10 improve wildcard character class lists |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 17 | " 2025 May 21 improve supported KornShell features |
hakkadaikon | 152a450 | 2025-06-16 19:54:37 +0200 | [diff] [blame] | 18 | " 2025 Jun 16 change how sh_fold_enabled is reset (#17557) |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 19 | " Version: 208 |
Christian Brabandt | f9ca139 | 2024-02-19 20:37:11 +0100 | [diff] [blame] | 20 | " Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 21 | " For options and settings, please use: :help ft-sh-syntax |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 22 | " This file includes many ideas from Eric Brunet (eric.brunet@ens.fr) and heredoc fixes from Felipe Contreras |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 24 | " quit when a syntax file was already loaded {{{1 |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 25 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | finish |
| 27 | endif |
| 28 | |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 29 | " Ensure this is set unless we find another shell |
| 30 | let b:is_sh = 1 |
| 31 | |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 32 | " If the shell script itself specifies which shell to use, use it |
Aliaksei Budavei | 5c84d12 | 2025-04-10 21:52:14 +0200 | [diff] [blame] | 33 | let s:shebang = getline(1) |
| 34 | |
| 35 | if s:shebang =~ '^#!.\{-2,}\<ksh\>' |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 36 | " The binary is too ambiguous (i.e. '/bin/ksh' or some such). |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 37 | let b:is_kornshell = 1 |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 38 | let b:generic_korn = 1 |
| 39 | elseif s:shebang =~ '^#!.\{-2,}\<ksh93u\+\>' |
| 40 | " ksh93u+ (or 93u-) release (still much too common to encounter) |
| 41 | let b:is_kornshell = 1 |
| 42 | let b:is_ksh93u = 1 |
| 43 | elseif s:shebang =~ '^#!.\{-2,}\<ksh93v\>' |
| 44 | " ksh93v- alpha or beta |
| 45 | let b:is_kornshell = 1 |
| 46 | let b:is_ksh93v = 1 |
| 47 | elseif s:shebang =~ '^#!.\{-2,}\<ksh93\>' |
| 48 | " Could be any ksh93 release |
| 49 | let b:is_kornshell = 1 |
| 50 | let b:is_ksh93 = 1 |
| 51 | elseif s:shebang =~ '^#!.\{-2,}\<ksh2020\>' |
| 52 | let b:is_kornshell = 1 |
| 53 | let b:is_ksh2020 = 1 |
| 54 | elseif s:shebang =~ '^#!.\{-2,}\<ksh88\>' |
| 55 | " The actual AT&T ksh88 and its feature set is assumed. |
| 56 | let b:is_kornshell = 1 |
| 57 | let b:is_ksh88 = 1 |
| 58 | elseif s:shebang =~ '^#!.\{-2,}\<mksh\>' |
| 59 | " MirBSD Korn Shell |
| 60 | let b:is_kornshell = 1 |
| 61 | let b:is_mksh = 1 |
Aliaksei Budavei | 5c84d12 | 2025-04-10 21:52:14 +0200 | [diff] [blame] | 62 | elseif s:shebang =~ '^#!.\{-2,}\<bash\>' |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 63 | let b:is_bash = 1 |
Aliaksei Budavei | 5c84d12 | 2025-04-10 21:52:14 +0200 | [diff] [blame] | 64 | elseif s:shebang =~ '^#!.\{-2,}\<dash\>' |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 65 | let b:is_dash = 1 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 66 | " handling /bin/sh with is_kornshell/is_sh {{{1 |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 67 | " b:is_sh will be set when "#! /bin/sh" is found; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 68 | " However, it often is just a masquerade by bash (typically Linux) |
| 69 | " or kornshell (typically workstations with Posix "sh"). |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 70 | " So, when the user sets "g:is_kornshell", "g:is_bash", |
| 71 | " "g:is_posix" or "g:is_dash", a b:is_sh is converted into |
| 72 | " b:is_kornshell/b:is_bash/b:is_posix/b:is_dash, respectively. |
| 73 | elseif !exists("b:is_kornshell") && !exists("b:is_bash") && !exists("b:is_posix") && !exists("b:is_dash") |
| 74 | if exists("g:is_kornshell") |
| 75 | let b:is_kornshell= 1 |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 76 | let b:generic_korn = 1 |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 77 | elseif exists("g:is_bash") |
| 78 | let b:is_bash= 1 |
| 79 | elseif exists("g:is_dash") |
| 80 | let b:is_dash= 1 |
| 81 | elseif exists("g:is_posix") |
| 82 | let b:is_posix= 1 |
| 83 | elseif exists("g:is_sh") |
| 84 | let b:is_sh= 1 |
| 85 | else |
| 86 | " user did not specify which shell to use, and |
| 87 | " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous. |
| 88 | " Assuming /bin/sh is executable, and if its a link, find out what it links to. |
| 89 | let s:shell = "" |
| 90 | if executable("/bin/sh") |
| 91 | let s:shell = resolve("/bin/sh") |
| 92 | elseif executable("/usr/bin/sh") |
| 93 | let s:shell = resolve("/usr/bin/sh") |
Bram Moolenaar | 7fc904b | 2006-04-13 20:37:35 +0000 | [diff] [blame] | 94 | endif |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 95 | if s:shell =~ '\<ksh\>' |
| 96 | " The binary is too ambiguous (i.e. '/bin/ksh' or some such). |
| 97 | let b:is_kornshell = 1 |
| 98 | let b:generic_korn = 1 |
| 99 | elseif s:shell =~ '\<ksh93u\+\>' |
| 100 | " ksh93u+ (or 93u-) release (still much too common to encounter) |
| 101 | let b:is_kornshell = 1 |
| 102 | let b:is_ksh93u = 1 |
| 103 | elseif s:shell =~ '\<ksh93v\>' |
| 104 | " ksh93v- alpha or beta |
| 105 | let b:is_kornshell = 1 |
| 106 | let b:is_ksh93v = 1 |
| 107 | elseif s:shell =~ '\<ksh93\>' |
| 108 | " Could be any ksh93 release |
| 109 | let b:is_kornshell = 1 |
| 110 | let b:is_ksh93 = 1 |
| 111 | elseif s:shebang =~ '\<ksh2020\>' |
| 112 | let b:is_kornshell = 1 |
| 113 | let b:is_ksh2020 = 1 |
| 114 | elseif s:shell =~ '\<ksh88\>' |
| 115 | " The actual AT&T ksh88 and its feature set is assumed. |
| 116 | let b:is_kornshell = 1 |
| 117 | let b:is_ksh88 = 1 |
| 118 | elseif s:shell =~ '\<mksh\>' |
| 119 | " MirBSD Korn Shell |
| 120 | let b:is_kornshell = 1 |
| 121 | let b:is_mksh = 1 |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 122 | elseif s:shell =~ '\<bash\>' |
| 123 | let b:is_bash = 1 |
| 124 | elseif s:shell =~ '\<dash\>' |
| 125 | let b:is_dash = 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | else |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 127 | let b:is_posix = 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 128 | endif |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 129 | unlet s:shell |
| 130 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | endif |
| 132 | |
Aliaksei Budavei | 5c84d12 | 2025-04-10 21:52:14 +0200 | [diff] [blame] | 133 | unlet s:shebang |
| 134 | |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 135 | " if b:is_dash, set b:is_posix too |
| 136 | if exists("b:is_dash") |
| 137 | let b:is_posix= 1 |
| 138 | endif |
| 139 | |
Mohamed Akram | 51a06ec | 2025-03-21 17:52:08 +0100 | [diff] [blame] | 140 | if exists("b:is_kornshell") || exists("b:is_bash") |
| 141 | if exists("b:is_sh") |
| 142 | unlet b:is_sh |
| 143 | endif |
| 144 | endif |
| 145 | |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 146 | " set up default g:sh_fold_enabled {{{1 |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 147 | " ================================ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 148 | if !exists("g:sh_fold_enabled") |
| 149 | let g:sh_fold_enabled= 0 |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 150 | elseif g:sh_fold_enabled != 0 && !has("folding") |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 151 | echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support" |
hakkadaikon | 152a450 | 2025-06-16 19:54:37 +0200 | [diff] [blame] | 152 | let g:sh_fold_enabled= 0 |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 153 | endif |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 154 | let s:sh_fold_functions= and(g:sh_fold_enabled,1) |
| 155 | let s:sh_fold_heredoc = and(g:sh_fold_enabled,2) |
| 156 | let s:sh_fold_ifdofor = and(g:sh_fold_enabled,4) |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 157 | if g:sh_fold_enabled && &fdm == "manual" |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 158 | " Given that the user provided g:sh_fold_enabled |
| 159 | " AND g:sh_fold_enabled is manual (usual default) |
| 160 | " implies a desire for syntax-based folding |
| 161 | setl fdm=syntax |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 162 | endif |
| 163 | |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 164 | " set up the syntax-highlighting for iskeyword |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 165 | if (v:version == 704 && has("patch-7.4.1142")) || v:version > 704 |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 166 | if !exists("g:sh_syntax_isk") || (exists("g:sh_syntax_isk") && g:sh_syntax_isk) |
| 167 | if exists("b:is_bash") |
| 168 | exe "syn iskeyword ".&iskeyword.",-,:" |
| 169 | else |
| 170 | exe "syn iskeyword ".&iskeyword.",-" |
| 171 | endif |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 172 | endif |
Bram Moolenaar | e0fa374 | 2016-02-20 15:47:01 +0100 | [diff] [blame] | 173 | endif |
| 174 | |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 175 | " Set up folding commands for shell {{{1 |
| 176 | " ================================= |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 177 | sil! delc ShFoldFunctions |
| 178 | sil! delc ShFoldHereDoc |
| 179 | sil! delc ShFoldIfDoFor |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 180 | if s:sh_fold_functions |
| 181 | com! -nargs=* ShFoldFunctions <args> fold |
| 182 | else |
| 183 | com! -nargs=* ShFoldFunctions <args> |
| 184 | endif |
| 185 | if s:sh_fold_heredoc |
| 186 | com! -nargs=* ShFoldHereDoc <args> fold |
| 187 | else |
| 188 | com! -nargs=* ShFoldHereDoc <args> |
| 189 | endif |
| 190 | if s:sh_fold_ifdofor |
| 191 | com! -nargs=* ShFoldIfDoFor <args> fold |
| 192 | else |
| 193 | com! -nargs=* ShFoldIfDoFor <args> |
| 194 | endif |
| 195 | |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 196 | " Generate bracket expression items {{{1 |
| 197 | " ================================= |
| 198 | " Note that the following function can be invoked as many times as necessary |
| 199 | " provided that these constraints hold for the passed dictionary argument: |
| 200 | " - every time a unique group-name value is assigned to the "itemGroup" key; |
| 201 | " - only ONCE either the "extraArgs" key is not entered or it is entered and |
| 202 | " its value does not have "contained" among other optional arguments (":help |
| 203 | " :syn-arguments"). |
| 204 | fun! s:GenerateBracketExpressionItems(dict) abort |
| 205 | let itemGroup = a:dict.itemGroup |
| 206 | let bracketGroup = a:dict.bracketGroup |
| 207 | let invGroup = itemGroup . 'Inv' |
| 208 | let skipLeftBracketGroup = itemGroup . 'SkipLeftBracket' |
| 209 | let skipRightBracketGroup = itemGroup . 'SkipRightBracket' |
| 210 | let extraArgs = has_key(a:dict, 'extraArgs') ? a:dict.extraArgs : '' |
| 211 | |
| 212 | " Make the leading "[!^]" stand out in a NON-matching expression. |
| 213 | exec 'syn match ' . invGroup . ' contained "\[\@<=[!^]"' |
| 214 | |
| 215 | " Set up indirections for unbalanced-bracket highlighting. |
| 216 | exec 'syn region ' . skipRightBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" matchgroup=shCollSymb end="\[\.[^]]\{-}\][^]]\{-}\.\]" matchgroup=' . itemGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . invGroup |
| 217 | exec 'syn region ' . skipLeftBracketGroup . ' contained matchgroup=' . bracketGroup . ' start="\[\%([!^]\=\\\=\]\)\@=" skip="[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\%(\[[:.=]\@!\)\@=" matchgroup=' . itemGroup . ' end="\[[:.=]\@!" contains=@shBracketExprList,shDoubleQuote,' . invGroup |
| 218 | |
| 219 | " Look for a general matching expression. |
| 220 | exec 'syn region ' . itemGroup . ' matchgroup=' . bracketGroup . ' start="\[\S\@=" end="\]" contains=@shBracketExprList,shDoubleQuote ' . extraArgs |
| 221 | " Look for a general NON-matching expression. |
| 222 | exec 'syn region ' . itemGroup . ' matchgroup=' . bracketGroup . ' start="\[[!^]\@=" end="\]" contains=@shBracketExprList,shDoubleQuote,' . invGroup . ' ' . extraArgs |
| 223 | |
| 224 | " Accommodate unbalanced brackets in bracket expressions. The supported |
| 225 | " syntax for a plain "]" can be: "[]ws]" and "[^]ws]"; or, "[ws[.xs]ys.]zs]" |
| 226 | " and "[^ws[.xs]ys.]zs]"; see §9.3.5 RE Bracket Expression (in XBD). |
| 227 | exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipRightBracketGroup . ' ' . extraArgs |
| 228 | " Strive to handle "[]...[]" etc. |
| 229 | exec 'syn region ' . itemGroup . ' matchgroup=NONE start="\[[!^]\=\\\=\]\%(\[[^]]\+\]\|[^]]\)\{-}\[[:.=]\@!" matchgroup=' . bracketGroup . ' end="\]" contains=@shBracketExprList,shDoubleQuote,' . skipLeftBracketGroup . ' ' . extraArgs |
| 230 | |
| 231 | if !exists("g:skip_sh_syntax_inits") |
| 232 | exec 'hi def link ' . skipLeftBracketGroup . ' ' . itemGroup |
| 233 | exec 'hi def link ' . skipRightBracketGroup . ' ' . itemGroup |
| 234 | exec 'hi def link ' . invGroup . ' Underlined' |
| 235 | endif |
| 236 | endfun |
| 237 | |
| 238 | call s:GenerateBracketExpressionItems({'itemGroup': 'shBracketExpr', 'bracketGroup': 'shBracketExprDelim'}) |
| 239 | |
Bram Moolenaar | cd71fa3 | 2005-03-11 22:46:48 +0000 | [diff] [blame] | 240 | " sh syntax is case sensitive {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 241 | syn case match |
| 242 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 243 | " Clusters: contains=@... clusters {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 244 | "================================== |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 245 | syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 246 | if exists("b:is_kornshell") || exists("b:is_bash") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 247 | syn cluster ErrorList add=shDTestError |
| 248 | endif |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 249 | syn cluster shArithParenList contains=shArithmetic,shArithParen,shCaseEsac,shComment,shDeref,shDerefVarArray,shDo,shDerefSimple,shEcho,shEscape,shExpr,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shHereString,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement,shIf,shFor,shFunctionKey,shFunctionOne,shFunctionTwo |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 250 | syn cluster shArithList contains=@shArithParenList,shParenError |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 251 | syn cluster shBracketExprList contains=shCharClassOther,shCharClass,shCollSymb,shEqClass |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 252 | syn cluster shCaseEsacList contains=shCaseStart,shCaseLabel,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial,shCaseRange |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 253 | syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shComment,shDblBrace,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 254 | if exists("b:is_kornshell") || exists("b:is_bash") |
Lucien Grondin | 1858e2b | 2023-11-02 20:33:56 +0100 | [diff] [blame] | 255 | syn cluster shCaseList add=shForPP,shDblParen |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 256 | endif |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 257 | syn cluster shCommandSubList contains=shAlias,shArithmetic,shBracketExpr,shCmdParenRegion,shCommandSub,shComment,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shHereDoc,shNumber,shOperator,shOption,shPosnParm,shHereString,shRedir,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable |
Bram Moolenaar | 572cb56 | 2005-08-05 21:35:02 +0000 | [diff] [blame] | 258 | syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 259 | " COMBAK: removing shEscape from shDblQuoteList fails ksh04:43 -- Jun 09, 2022: I don't see the problem with ksh04, so am reinstating shEscape |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 260 | syn cluster shDblQuoteList contains=shArithmetic,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shDeref,shDerefSimple,shEscape,shPosnParm,shCtrlSeq,shSpecial,shSpecialDQ |
Bram Moolenaar | acb4f22 | 2016-01-10 15:59:26 +0100 | [diff] [blame] | 261 | syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPSR,shDerefPPS |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 262 | syn cluster shDerefVarList contains=shDerefOffset,shDerefOp,shDerefVarArray,shDerefOpError |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 263 | syn cluster shEchoList contains=shArithmetic,shBracketExpr,shCommandSub,shCommandSubBQ,shDerefVarArray,shSubshare,shValsub,shDeref,shDerefSimple,shEscape,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote |
| 264 | syn cluster shExprList1 contains=shBracketExpr,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 265 | syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 266 | syn cluster shFunctionList contains=shBracketExpr,@shCommandSubList,shCaseEsac,shColon,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shOption,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shCtrlSeq |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 267 | if exists("b:is_kornshell") || exists("b:is_bash") |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 268 | syn cluster shFunctionList add=shRepeat,shDblBrace,shDblParen,shForPP |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 269 | syn cluster shDerefList add=shCommandSubList,shEchoDeref |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 270 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 271 | syn cluster shHereBeginList contains=@shCommandSubList |
| 272 | syn cluster shHereList contains=shBeginHere,shHerePayload |
| 273 | syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 274 | syn cluster shIdList contains=shArithmetic,shCommandSub,shCommandSubBQ,shDerefVarArray,shSubshare,shValsub,shWrapLineOperator,shSetOption,shComment,shDeref,shDerefSimple,shHereString,shNumber,shOperator,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial,shAtExpr |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 275 | syn cluster shIfList contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey,shFunctionOne,shFunctionTwo |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 276 | syn cluster shLoopList contains=@shCaseList,@shErrorList,shCaseEsac,shConditional,shDblBrace,shExpr,shFor,shIf,shOption,shSet,shTest,shTestOpr,shTouch |
| 277 | if exists("b:is_kornshell") || exists("b:is_bash") |
Lucien Grondin | a390e98 | 2023-10-28 21:40:48 +0200 | [diff] [blame] | 278 | syn cluster shLoopList add=shForPP,shDblParen |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 279 | endif |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 280 | syn cluster shPPSLeftList contains=shAlias,shArithmetic,shBracketExpr,shCmdParenRegion,shCommandSub,shSubshare,shValsub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shEcho,shEscape,shExDoubleQuote,shExpr,shExSingleQuote,shHereDoc,shNumber,shOperator,shOption,shPosnParm,shHereString,shRedir,shSingleQuote,shSpecial,shStatement,shSubSh,shTest,shVariable |
Bram Moolenaar | dd60c36 | 2023-02-27 15:49:53 +0000 | [diff] [blame] | 281 | syn cluster shPPSRightList contains=shDeref,shDerefSimple,shEscape,shPosnParm |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 282 | syn cluster shSubShList contains=shBracketExpr,@shCommandSubList,shCommandSubBQ,shSubshare,shValsub,shCaseEsac,shColon,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shHereString,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator |
| 283 | syn cluster shTestList contains=shArithmetic,shBracketExpr,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shCtrlSeq,shDeref,shDerefSimple,shDoubleQuote,shSpecialDQ,shExDoubleQuote,shExpr,shExSingleQuote,shNumber,shOperator,shSingleQuote,shTest,shTestOpr |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 284 | syn cluster shNoZSList contains=shSpecialNoZS |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 285 | syn cluster shForList contains=shTestOpr,shNumber,shDerefSimple,shDeref,shCommandSub,shCommandSubBQ,shSubshare,shValsub,shArithmetic |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 286 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 287 | " Echo: {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 288 | " ==== |
| 289 | " This one is needed INSIDE a CommandSub, so that `echo bla` be correct |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 290 | if (exists("b:is_kornshell") && !exists("b:is_ksh88")) |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 291 | syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 end="\ze[ \t\n;]}" contains=@shEchoList skipwhite nextgroup=shQuickComment |
| 292 | syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 end="\ze[ \t\n;]}" contains=@shEchoList skipwhite nextgroup=shQuickComment |
| 293 | else |
| 294 | syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment |
| 295 | syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()`]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment |
| 296 | endif |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 297 | if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") |
| 298 | syn region shEchoDeref contained matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment |
| 299 | syn region shEchoDeref contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" end="[<>;&|()`}]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment |
| 300 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 301 | syn match shEchoQuote contained '\%(\\\\\)*\\["`'()]' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 302 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 303 | " This must be after the strings, so that ... \" will be correct |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 304 | syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=shBracketExpr,shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shExDoubleQuote,shDoubleQuote,shCtrlSeq |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 305 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 306 | " Alias: {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 307 | " ===== |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 308 | if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 309 | syn match shStatement "\<alias\>" |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 310 | syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]*\)\@=" skip="\\$" end="\>\|`" |
| 311 | syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]*=\)\@=" skip="\\$" end="=" |
| 312 | " syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+\)\@=" skip="\\$" end="\>\|`" |
| 313 | " syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\h[-._[:alnum:]]\+=\)\@=" skip="\\$" end="=" |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 314 | |
| 315 | " Touch: {{{1 |
| 316 | " ===== |
Bram Moolenaar | 6d5ad4c | 2016-10-27 17:00:16 +0200 | [diff] [blame] | 317 | syn match shTouch '\<touch\>[^;#]*' skipwhite nextgroup=shComment contains=shTouchCmd,shDoubleQuote,shSingleQuote,shDeref,shDerefSimple |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 318 | syn match shTouchCmd '\<touch\>' contained |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 319 | endif |
| 320 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 321 | " Error Codes: {{{1 |
| 322 | " ============ |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 323 | if !exists("g:sh_no_error") |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 324 | syn match shDoError "\<done\>" |
| 325 | syn match shIfError "\<fi\>" |
| 326 | syn match shInError "\<in\>" |
| 327 | syn match shCaseError ";;" |
| 328 | syn match shEsacError "\<esac\>" |
| 329 | syn match shCurlyError "}" |
| 330 | syn match shParenError ")" |
| 331 | syn match shOK '\.\(done\|fi\|in\|esac\)' |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 332 | if exists("b:is_kornshell") || exists("b:is_bash") |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 333 | syn match shDTestError "]]" |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 334 | endif |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 335 | syn match shTestError "]" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 336 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 337 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 338 | " Options: {{{1 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 339 | " ==================== |
Bram Moolenaar | 7db8f6f | 2016-03-29 23:12:46 +0200 | [diff] [blame] | 340 | syn match shOption "\s\zs[-+][-_a-zA-Z#@]\+" |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 341 | syn match shOption "\s\zs--[^ \t$=`'"|);]\+" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 342 | |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 343 | " File Redirection Highlighted As Operators: {{{1 |
| 344 | "=========================================== |
| 345 | syn match shRedir "\d\=>\(&[-0-9]\)\=" |
| 346 | syn match shRedir "\d\=>>-\=" |
| 347 | syn match shRedir "\d\=<\(&[-0-9]\)\=" |
| 348 | syn match shRedir "\d<<-\=" |
| 349 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 350 | " Operators: {{{1 |
| 351 | " ========== |
Bram Moolenaar | 7263a77 | 2007-05-10 17:35:54 +0000 | [diff] [blame] | 352 | syn match shOperator "<<\|>>" contained |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 353 | syn match shOperator "[!&;|]" contained |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 354 | syn match shOperator "[-=/*+%]\==" skipwhite nextgroup=shPattern |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 355 | syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 356 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 357 | " Subshells: {{{1 |
| 358 | " ========== |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 359 | syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2 nextgroup=shSpecialNxt |
| 360 | syn region shSubSh transparent matchgroup=shSubShRegion start="[^(]\zs(" end=")" contains=@shSubShList nextgroup=shSpecialNxt |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 361 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 362 | " Tests: {{{1 |
| 363 | "======= |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 364 | syn region shExpr matchgroup=shRange start="\[\s\@=" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 365 | syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1 |
Doug Kearns | f57c065 | 2025-04-30 20:04:28 +0200 | [diff] [blame] | 366 | syn region shNoQuote start='\S' skip='\%(\\\\\)*\\.' end='\ze\s' end="\ze['"]" contained contains=shBracketExpr,shDerefSimple,shDeref,shEscape |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 367 | syn match shAstQuote contained '\*\ze"' nextgroup=shString |
Bram Moolenaar | 541f92d | 2015-06-19 13:27:23 +0200 | [diff] [blame] | 368 | syn match shTestOpr contained '[^-+/%]\zs=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 369 | syn match shTestOpr contained "<=\|>=\|!=\|==\|=\~\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]" |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 370 | syn match shTestPattern contained '\w\+' |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 371 | syn region shTestDoubleQuote contained start='\%(\%(\\\\\)*\\\)\@<!"' skip=+\\\\\|\\"+ end='"' contains=shDeref,shDerefSimple,shDerefSpecial |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 372 | syn match shTestSingleQuote contained '\\.' nextgroup=shTestSingleQuote |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 373 | syn match shTestSingleQuote contained "'[^']*'" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 374 | if exists("b:is_kornshell") || exists("b:is_bash") |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 375 | syn region shDblBrace matchgroup=Delimiter start="\[\[\s\@=" skip=+\%(\\\\\)*\\$+ end="\]\]" contains=@shTestList,shAstQuote,shNoQuote,shComment |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 376 | syn region shDblParen matchgroup=Delimiter start="((" skip=+\%(\\\\\)*\\$+ end="))" contains=@shTestList,shComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 377 | endif |
| 378 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 379 | " Character Class In Range: {{{1 |
| 380 | " ========================= |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 381 | syn match shCharClassOther contained "\[:\w\{-}:\]" |
Doug Kearns | 839b79e | 2025-05-10 20:57:10 +0200 | [diff] [blame] | 382 | syn match shCharClass contained "\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|xdigit\):\]" |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 383 | syn match shCollSymb contained "\[\..\{-}\.\]" |
| 384 | syn match shEqClass contained "\[=.\{-}=\]" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 385 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 386 | " Loops: do, if, while, until {{{1 |
| 387 | " ====== |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 388 | ShFoldIfDoFor syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList |
| 389 | ShFoldIfDoFor syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>" contains=@shIfList |
| 390 | ShFoldIfDoFor syn region shFor matchgroup=shLoop start="\<for\ze\_s\s*\%(((\)\@!" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 391 | if exists("b:is_kornshell") || exists("b:is_bash") |
| 392 | ShFoldIfDoFor syn region shForPP matchgroup=shLoop start='\<for\>\_s*((' end='))' contains=@shForList |
| 393 | endif |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 394 | |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 395 | if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 396 | syn cluster shCaseList add=shRepeat |
| 397 | syn cluster shFunctionList add=shRepeat |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 398 | syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace |
| 399 | syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace |
| 400 | if !exists("b:is_posix") |
| 401 | syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList |
| 402 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 403 | else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 404 | syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList |
| 405 | syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 406 | endif |
Bram Moolenaar | 572cb56 | 2005-08-05 21:35:02 +0000 | [diff] [blame] | 407 | syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList |
| 408 | syn match shComma contained "," |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 409 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 410 | " Case: case...esac {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 411 | " ==== |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 412 | syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote |
| 413 | syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 414 | syn match shCaseLabel contained skipwhite "\%(\\.\|[-a-zA-Z0-9_*.]\)\+" contains=shBracketExpr |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 415 | if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_ksh93u") && !exists("b:is_ksh93v") && !exists("b:is_ksh2020")) |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 416 | ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end=";&" end=";;&" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 417 | elseif exists("b:is_kornshell") |
| 418 | ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end=";&" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment |
Eisuke Kawashima | 54cb514 | 2025-01-18 10:11:28 +0100 | [diff] [blame] | 419 | else |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 420 | ShFoldIfDoFor syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 421 | endif |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 422 | ShFoldIfDoFor syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 423 | |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 424 | syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 425 | if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88")) |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 426 | syn region shCaseExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 427 | elseif !exists("g:sh_no_error") |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 428 | syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained |
| 429 | endif |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 430 | syn region shCaseSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained |
| 431 | syn region shCaseDoubleQuote matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 432 | syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 433 | call s:GenerateBracketExpressionItems({'itemGroup': 'shCaseRange', 'bracketGroup': 'shBracketExprDelim', 'extraArgs': 'skip=+\\\\+ contained'}) |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 434 | if exists("b:is_bash") |
Doug Kearns | 839b79e | 2025-05-10 20:57:10 +0200 | [diff] [blame] | 435 | syn match shCharClass "\[:\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained |
| 436 | elseif exists("b:is_kornshell") |
| 437 | syn match shCharClass "\[:\%(alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|word\|xdigit\):\]" contained |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 438 | endif |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 439 | " Misc: {{{1 |
| 440 | "====== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 441 | syn match shWrapLineOperator "\\$" |
Bram Moolenaar | 93a1df2 | 2018-09-10 11:51:50 +0200 | [diff] [blame] | 442 | syn region shCommandSubBQ start="`" skip="\\\\\|\\." end="`" contains=shBQComment,@shCommandSubList |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 443 | "COMBAK: see ksh13:50 |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 444 | "syn match shEscape contained '\%(^\)\@!\%(\\\\\)*\\.' nextgroup=shSingleQuote,shDoubleQuote,shComment |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 445 | "COMBAK: see sh11:27 |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 446 | syn match shEscape contained '\%(^\)\@!\%(\\\\\)*\\.' nextgroup=shComment |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 447 | "COMBAK: see ksh13:53 |
| 448 | "syn match shEscape contained '\%(^\)\@!\%(\\\\\)*\\.' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 449 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 450 | " $() and $(()): {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 451 | " $(..) is not supported by sh (Bourne shell). However, apparently |
| 452 | " some systems (HP?) have as their /bin/sh a (link to) Korn shell |
| 453 | " (ie. Posix compliant shell). /bin/ksh should work for those |
| 454 | " systems too, however, so the following syntax will flag $(..) as |
| 455 | " an Error under /bin/sh. By consensus of vimdev'ers! |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 456 | if exists("b:is_kornshell") || exists("b:is_bash") || exists("b:is_posix") |
Doug Kearns | 6099db9 | 2025-04-03 21:13:39 +0200 | [diff] [blame] | 457 | syn region shCommandSub matchgroup=shCmdSubRegion start="\$((\@!" skip='\\\\\|\\.' end=")" contains=@shCommandSubList |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 458 | if exists("b:is_kornshell") |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 459 | if !exists("b:is_ksh88") |
| 460 | if exists("b:is_mksh") |
| 461 | syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n]" skip='\\\\\|\\.' end="\zs[ \t\n;]}" contains=@shCommandSubList |
| 462 | else |
| 463 | syn region shSubshare matchgroup=shCmdSubRegion start="\${\ze[ \t\n<]" skip='\\\\\|\\.' end="\zs[ \t\n;]}" contains=@shCommandSubList |
| 464 | endif |
| 465 | endif |
| 466 | if exists("b:is_mksh") || exists("b:generic_korn") |
| 467 | syn region shValsub matchgroup=shCmdSubRegion start="\${|" skip='\\\\\|\\.' end="}" contains=@shCommandSubList |
| 468 | endif |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 469 | endif |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 470 | syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList |
Bram Moolenaar | 61d35bd | 2012-03-28 20:51:51 +0200 | [diff] [blame] | 471 | syn region shArithmetic matchgroup=shArithRegion start="\$\[" skip='\\\\\|\\.' end="\]" contains=@shArithList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 472 | syn match shSkipInitWS contained "^\s\+" |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 473 | syn region shArithParen matchgroup=shArithRegion contained start="(" end=")" contains=@shArithParenList |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 474 | elseif !exists("g:sh_no_error") |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 475 | syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 476 | endif |
dkearns | 1bdc943 | 2024-03-05 05:14:08 +1100 | [diff] [blame] | 477 | syn region shCmdParenRegion matchgroup=shCmdSubRegion start="((\@!" skip='\\\\\|\\.' end=")" contains=@shCommandSubList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 478 | |
| 479 | if exists("b:is_bash") |
| 480 | syn cluster shCommandSubList add=bashSpecialVariables,bashStatement |
| 481 | syn cluster shCaseList add=bashAdminStatement,bashStatement |
Eisuke Kawashima | 54cb514 | 2025-01-18 10:11:28 +0100 | [diff] [blame] | 482 | syn keyword bashSpecialVariables contained auto_resume BASH BASH_ALIASES BASH_ARGC BASH_ARGV BASH_CMDS BASH_COMMAND BASH_ENV BASH_EXECUTION_STRING BASH_LINENO BASHOPTS BASHPID BASH_REMATCH BASH_SOURCE BASH_SUBSHELL BASH_VERSINFO BASH_VERSION BASH_XTRACEFD CDPATH COLUMNS COMP_CWORD COMP_KEY COMP_LINE COMP_POINT COMPREPLY COMP_TYPE COMP_WORDBREAKS COMP_WORDS COPROC COPROC_PID DIRSTACK EMACS ENV EUID FCEDIT FIGNORE FUNCNAME FUNCNEST GLOBIGNORE GROUPS histchars HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HISTTIMEFORMAT HOME HOSTFILE HOSTNAME HOSTTYPE IFS IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LINENO LINES MACHTYPE MAIL MAILCHECK MAILPATH MAPFILE OLDPWD OPTARG OPTERR OPTIND OSTYPE PATH PIPESTATUS POSIXLY_CORRECT PPID PROMPT_COMMAND PS0 PS1 PS2 PS3 PS4 PWD RANDOM READLINE_LINE READLINE_POINT REPLY SECONDS SHELL SHELLOPTS SHLVL TIMEFORMAT TIMEOUT TMPDIR UID |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 483 | syn keyword bashStatement basename cat chgrp chmod chown cksum clear cmp comm command compgen complete cp cut date dirname du egrep expr fgrep find fmt fold getconf gnufind gnugrep grep head iconv id join less ln logname ls md5sum mkdir mkfifo mknod mktemp mv od paste pathchk readlink realpath rev rm rmdir rpm sed sha1sum sha224sum sha256sum sha384sum sha512sum sleep sort strip stty sum sync tail tee tr tty uname uniq wc which xargs xgrep |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 484 | syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop |
| 485 | endif |
| 486 | |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 487 | if exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 488 | syn cluster shCommandSubList add=kshSpecialVariables,kshStatement |
| 489 | syn cluster shCaseList add=kshStatement |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 490 | syn keyword kshSpecialVariables contained CDPATH COLUMNS EDITOR ENV FCEDIT FIGNORE FPATH HISTCMD HISTEDIT HISTFILE HISTSIZE HOME IFS JOBMAX KSH_VERSION LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_TIME LINENO LINES MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTIND PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELL SHLVL TMOUT VISUAL |
| 491 | syn keyword kshStatement basename cat chgrp chmod chown cksum clear cmp comm command cp cut date dirname du egrep expr fgrep find fmt fold grep head iconv id join killall less ln logname ls md5sum mkdir mknod mkfifo mktemp mv nice od paste pathchk printenv readlink realpath rev rm rmdir sed setgroups setsenv sha1sum sha224sum sha256sum sha384sum sha512sum sort strip stty sum sync tail tee tput tr tty uname uniq wc which xargs xgrep |
| 492 | if exists("b:is_ksh88") |
| 493 | syn keyword kshSpecialVariables contained ERRNO |
| 494 | elseif exists("b:is_mksh") |
| 495 | syn keyword kshSpecialVariables contained BASHPID EPOCHREALTIME EXECSHELL KSHEGID KSHGID KSHUID KSH_MATCH PATHSEP PGRP PIPESTATUS TMPDIR USER_ID |
| 496 | syn keyword kshStatement bind rename |
| 497 | elseif exists("b:is_ksh93v") || exists("b:is_ksh2020") |
| 498 | syn keyword kshSpecialVariables contained SH_OPTIONS COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMP_KEY COMPREPLY COMP_WORDBREAKS COMP_TYPE |
| 499 | syn keyword kshStatement compgen complete |
| 500 | if exists("b:is_ksh93v") |
| 501 | syn keyword kshSpecialVariables contained VPATH CSWIDTH |
| 502 | syn keyword kshStatement vmstate alarm fds pids poll sha2sum |
| 503 | endif |
| 504 | elseif exists("b:is_ksh93u") |
| 505 | " ksh93u+ |
| 506 | syn keyword kshSpecialVariables contained VPATH CSWIDTH |
| 507 | syn keyword kshStatement alarm fds pids vmstate |
| 508 | else |
| 509 | " 'ksh' is ambiguous; include everything |
| 510 | syn keyword kshSpecialVariables contained BASHPID EPOCHREALTIME EXECSHELL KSHEGID KSHGID KSHUID KSH_MATCH PATHSEP PGRP PIPESTATUS TMPDIR USER_ID SH_OPTIONS COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMP_KEY COMPREPLY COMP_WORDBREAKS COMP_TYPE VPATH SRANDOM CSWIDTH |
| 511 | if !exists("b:is_ksh93") |
| 512 | syn keyword kshSpecialVariables contained ERRNO |
| 513 | endif |
| 514 | syn keyword kshStatement vmstate alarm fds pids poll sha2sum alarm eloop fds mkservice pids compgen complete bind rename |
| 515 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 516 | endif |
| 517 | |
| 518 | syn match shSource "^\.\s" |
| 519 | syn match shSource "\s\.\s" |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 520 | "syn region shColon start="^\s*:" end="$" end="\s#"me=e-2 contains=@shColonList |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 521 | "syn region shColon start="^\s*\zs:" end="$" end="\s#"me=e-2 |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 522 | if exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 523 | syn match shColon '^\s*\zs:' |
| 524 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 525 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 526 | " String And Character Constants: {{{1 |
| 527 | "================================ |
Bram Moolenaar | 7db8f6f | 2016-03-29 23:12:46 +0200 | [diff] [blame] | 528 | syn match shNumber "\<\d\+\>#\=" |
Bram Moolenaar | bc8801c | 2016-08-02 21:04:33 +0200 | [diff] [blame] | 529 | syn match shNumber "\<-\=\.\=\d\+\>#\=" |
Bram Moolenaar | 802a0d9 | 2016-06-26 16:17:58 +0200 | [diff] [blame] | 530 | syn match shCtrlSeq "\\\d\d\d\|\\[abcfnrtv0]" contained |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 531 | if exists("b:is_bash") || exists("b:is_kornshell") |
Bram Moolenaar | 802a0d9 | 2016-06-26 16:17:58 +0200 | [diff] [blame] | 532 | syn match shSpecial "[^\\]\(\\\\\)*\zs\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained |
| 533 | syn match shSpecial "^\(\\\\\)*\zs\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 534 | syn region shExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial nextgroup=shSpecialNxt |
| 535 | syn region shExDoubleQuote matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,shSpecial nextgroup=shSpecialNxt |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 536 | elseif !exists("g:sh_no_error") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 537 | syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial |
Bram Moolenaar | e90ee31 | 2010-08-05 22:08:47 +0200 | [diff] [blame] | 538 | syn region shExDoubleQuote matchGroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial |
Bram Moolenaar | df177f6 | 2005-02-22 08:39:57 +0000 | [diff] [blame] | 539 | endif |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 540 | syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell nextgroup=shSpecialStart,shSpecialSQ |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 541 | syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell nextgroup=shSpecialStart |
Bram Moolenaar | 802a0d9 | 2016-06-26 16:17:58 +0200 | [diff] [blame] | 542 | syn match shStringSpecial "[^[:print:] \t]" contained |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 543 | syn match shStringSpecial "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" nextgroup=shComment |
| 544 | syn match shSpecialSQ "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" contained nextgroup=shBkslshSnglQuote,@shNoZSList |
| 545 | syn match shSpecialDQ "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" contained nextgroup=shBkslshDblQuote,@shNoZSList |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 546 | syn match shSpecialStart "\%(\\\\\)*\\[\\"'`$()#]" contained nextgroup=shBkslshSnglQuote,shBkslshDblQuote,@shNoZSList |
Bram Moolenaar | 60cce2f | 2015-10-13 23:21:27 +0200 | [diff] [blame] | 547 | syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]" |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 548 | syn match shSpecialNoZS contained "\%(\\\\\)*\\[\\"'`$()#]" |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 549 | syn match shSpecialNxt contained "\\[\\"'`$()#]" |
Bram Moolenaar | 47e1395 | 2020-05-12 22:49:12 +0200 | [diff] [blame] | 550 | "syn region shBkslshSnglQuote contained matchgroup=shQuote start=+'+ end=+'+ contains=@Spell nextgroup=shSpecialStart |
| 551 | "syn region shBkslshDblQuote contained matchgroup=shQuote start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell nextgroup=shSpecialStart |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 552 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 553 | " Comments: {{{1 |
| 554 | "========== |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 555 | syn cluster shCommentGroup contains=shTodo,@Spell |
Bram Moolenaar | 6d5ad4c | 2016-10-27 17:00:16 +0200 | [diff] [blame] | 556 | if exists("b:is_bash") |
| 557 | syn match shTodo contained "\<\%(COMBAK\|FIXME\|TODO\|XXX\)\ze:\=\>" |
| 558 | else |
| 559 | syn keyword shTodo contained COMBAK FIXME TODO XXX |
| 560 | endif |
Bram Moolenaar | 5c73622 | 2010-01-06 20:54:52 +0100 | [diff] [blame] | 561 | syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup |
| 562 | syn match shComment "\s\zs#.*$" contains=@shCommentGroup |
Bram Moolenaar | 97d6249 | 2012-11-15 21:28:22 +0100 | [diff] [blame] | 563 | syn match shComment contained "#.*$" contains=@shCommentGroup |
Bram Moolenaar | 113cb51 | 2021-11-07 20:27:04 +0000 | [diff] [blame] | 564 | syn match shQuickComment contained "#.*$" contains=@shCommentGroup |
Bram Moolenaar | 93a1df2 | 2018-09-10 11:51:50 +0200 | [diff] [blame] | 565 | syn match shBQComment contained "#.\{-}\ze`" contains=@shCommentGroup |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 566 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 567 | " Here Documents: {{{1 |
Bram Moolenaar | d2ea7cf | 2021-05-30 20:54:13 +0200 | [diff] [blame] | 568 | " (modified by Felipe Contreras) |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 569 | " ========================================= |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 570 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc01 start="<<\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc01 end="^\z1$" contains=@shDblQuoteList |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 571 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc02 start="<<-\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc02 end="^\t*\z1$" contains=@shDblQuoteList |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 572 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc03 start="<<\s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc03 end="^\z1$" |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 573 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc04 start="<<-\s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc04 end="^\t*\z1$" |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 574 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc05 start="<<\s*'\z([^']\+\)'" matchgroup=shHereDoc05 end="^\z1$" |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 575 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc06 start="<<-\s*'\z([^']\+\)'" matchgroup=shHereDoc06 end="^\t*\z1$" |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 576 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc07 start="<<\s*\"\z([^"]\+\)\"" matchgroup=shHereDoc07 end="^\z1$" |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 577 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc08 start="<<-\s*\"\z([^"]\+\)\"" matchgroup=shHereDoc08 end="^\t*\z1$" |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 578 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc09 start="<<\s*\\\_$\_s*\z([^ \t|>]\+\)" matchgroup=shHereDoc09 end="^\z1$" contains=@shDblQuoteList |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 579 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc10 start="<<-\s*\\\_$\_s*\z([^ \t|>]\+\)" matchgroup=shHereDoc10 end="^\t*\z1$" contains=@shDblQuoteList |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 580 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc11 start="<<\s*\\\_$\_s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc11 end="^\z1$" |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 581 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc12 start="<<-\s*\\\_$\_s*\\\z([^ \t|>]\+\)" matchgroup=shHereDoc12 end="^\t*\z1$" |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 582 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc13 start="<<\s*\\\_$\_s*'\z([^']\+\)'" matchgroup=shHereDoc13 end="^\z1$" |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 583 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc14 start="<<-\s*\\\_$\_s*'\z([^']\+\)'" matchgroup=shHereDoc14 end="^\t*\z1$" |
Bram Moolenaar | 86b4816 | 2022-12-06 18:20:10 +0000 | [diff] [blame] | 584 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc15 start="<<\s*\\\_$\_s*\"\z([^"]\+\)\"" matchgroup=shHereDoc15 end="^\z1$" |
Bram Moolenaar | 71badf9 | 2023-04-22 22:40:14 +0100 | [diff] [blame] | 585 | ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc16 start="<<-\s*\\\_$\_s*\"\z([^"]\+\)\"" matchgroup=shHereDoc16 end="^\t*\z1$" |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 586 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 587 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 588 | " Here Strings: {{{1 |
| 589 | " ============= |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 590 | " available for: bash and ksh (except ksh88) but not if its a posix |
| 591 | if exists("b:is_bash") || ((exists("b:is_kornshell") && !exists("b:is_ksh88")) && !exists("b:is_posix")) |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 592 | syn match shHereString "<<<" skipwhite nextgroup=shCmdParenRegion |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 593 | endif |
| 594 | |
| 595 | " Identifiers: {{{1 |
| 596 | "============= |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 597 | syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 598 | syn match shVariable "\<\h\w*\ze=" nextgroup=shVarAssign |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 599 | if exists("b:is_bash") |
| 600 | " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". |
Doug Kearns | 87947a9 | 2025-05-06 17:59:25 +0200 | [diff] [blame] | 601 | syn region shArrayValue contained start="\[\%(..\{-}\]=\)\@=" end="\]=\@=" contains=@shArrayValueList nextgroup=shVarAssign |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 602 | syn cluster shArrayValueList contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,bashSpecialVariables,shParenError |
Doug Kearns | 87947a9 | 2025-05-06 17:59:25 +0200 | [diff] [blame] | 603 | syn region shArrayRegion contained matchgroup=shShellVariables start="(" skip='\\\\\|\\.' end=")" contains=@shArrayValueList,shArrayValue,shComment |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 604 | elseif (exists("b:is_kornshell") && !exists("b:is_ksh88")) |
Doug Kearns | 87947a9 | 2025-05-06 17:59:25 +0200 | [diff] [blame] | 605 | " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)". |
| 606 | syn region shArrayValue contained start="\[\%(..\{-}\]=\)\@=" end="\]=\@=" contains=@shArrayValueList nextgroup=shVarAssign |
| 607 | syn cluster shArrayValueList contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,kshSpecialVariables,shParenError |
| 608 | syn region shArrayRegion contained matchgroup=shShellVariables start="(" skip='\\\\\|\\.' end=")" contains=@shArrayValueList,shArrayValue,shComment,shArrayRegion |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 609 | endif |
| 610 | if exists("b:is_bash") || exists("b:is_kornshell") |
| 611 | syn match shVariable "\<\h\w*\%(\[..\{-}\]\)\=\ze\%([|^&*/%+-]\|[<^]<\|[>^]>\)\==" contains=shDerefVarArray nextgroup=shVarAssign |
| 612 | syn match shVarAssign contained "\%([|^&*/%+-]\|[<^]<\|[>^]>\)\==" nextgroup=shArrayRegion,shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 613 | else |
| 614 | syn match shVarAssign contained "=" nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote,shVar |
| 615 | endif |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 616 | syn match shVar contained "\h\w*" |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 617 | syn region shAtExpr contained start="@(" end=")" contains=@shIdList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 618 | if exists("b:is_bash") |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 619 | syn match shSet "^\s*set\ze\s\+$" |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 620 | syn region shSetList oneline matchgroup=shSet start="\<\%(declare\|local\|export\)\>\ze[/a-zA-Z_]\@!" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+#\|=" contains=@shIdList |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 621 | syn region shSetList oneline matchgroup=shSet start="\<\%(set\|unset\)\>[/a-zA-Z_]\@!" end="\ze[;|#)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+=" contains=@shIdList nextgroup=shComment |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 622 | elseif exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 623 | syn match shSet "^\s*set\ze\s\+$" |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 624 | if exists("b:is_dash") |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 625 | syn region shSetList oneline matchgroup=shSet start="\<\%(local\)\>\ze[/]\@!" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 626 | endif |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 627 | syn region shSetList oneline matchgroup=shSet start="\<\(export\)\>\ze[/]\@!" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 628 | syn region shSetList oneline matchgroup=shSet start="\<\%(set\|unset\>\)\ze[/a-zA-Z_]\@!" end="\ze[;|#)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList nextgroup=shComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 629 | else |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 630 | syn region shSetList oneline matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[/a-zA-Z_]\@!" end="\ze[;|#)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 631 | endif |
| 632 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 633 | " KornShell namespace: {{{1 |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 634 | if exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 635 | syn keyword shFunctionKey namespace skipwhite skipnl nextgroup=shFunctionTwo |
| 636 | endif |
| 637 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 638 | " Functions: {{{1 |
Bram Moolenaar | 690afe1 | 2017-01-28 18:34:47 +0100 | [diff] [blame] | 639 | if !exists("b:is_posix") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 640 | syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo |
| 641 | endif |
| 642 | |
| 643 | if exists("b:is_bash") |
Eisuke Kawashima | 54cb514 | 2025-01-18 10:11:28 +0100 | [diff] [blame] | 644 | syn keyword shFunctionKey coproc |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 645 | ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*[A-Za-z_0-9:][-a-zA-Z_0-9:]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 646 | ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\%(do\)\@!\&\<[A-Za-z_0-9:][-a-zA-Z_0-9:]*\>\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 647 | ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*[A-Za-z_0-9:][-a-zA-Z_0-9:]*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 648 | ShFoldFunctions syn region shFunctionFour matchgroup=shFunction start="\%(do\)\@!\&\<[A-Za-z_0-9:][-a-zA-Z_0-9:]*\>\s*\%(()\)\=\_s*)" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 649 | else |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 650 | ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 651 | ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\%(do\)\@!\&\<\h\w*\>\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 652 | ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\h\w*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
| 653 | ShFoldFunctions syn region shFunctionFour matchgroup=shFunction start="\%(do\)\@!\&\<\h\w*\>\s*\%(()\)\=\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 654 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 655 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 656 | " Parameter Dereferencing: {{{1 |
| 657 | " ======================== |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 658 | " Note: sh04 failure with following line |
| 659 | "if !exists("g:sh_no_error") && !(exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix")) |
| 660 | if !exists("g:sh_no_error") |
Bram Moolenaar | 91c4937 | 2016-05-08 09:50:29 +0200 | [diff] [blame] | 661 | syn match shDerefWordError "[^}$[~]" contained |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 662 | endif |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 663 | syn match shDerefSimple "\$\%(\h\w*\|\d\)" nextgroup=@shNoZSList |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 664 | if exists("b:is_kornshell") && !exists("b:is_ksh88") |
| 665 | if exists("b:is_mksh") |
| 666 | syn region shDeref matchgroup=PreProc start="\${\ze[^ \t\n|]" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart |
| 667 | elseif exists("b:generic_korn") |
| 668 | syn region shDeref matchgroup=PreProc start="\${\ze[^ \t\n<|]" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart |
| 669 | else |
| 670 | syn region shDeref matchgroup=PreProc start="\${\ze[^ \t\n<]" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart |
| 671 | endif |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 672 | else |
| 673 | syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray nextgroup=shSpecialStart |
| 674 | endif |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 675 | syn match shDerefSimple "\$[-#*@!?]" nextgroup=@shNoZSList |
| 676 | syn match shDerefSimple "\$\$" nextgroup=@shNoZSList |
Bram Moolenaar | 47e1395 | 2020-05-12 22:49:12 +0200 | [diff] [blame] | 677 | syn match shDerefSimple "\${\d}" nextgroup=@shNoZSList nextgroup=shSpecialStart |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 678 | if exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | 47e1395 | 2020-05-12 22:49:12 +0200 | [diff] [blame] | 679 | syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList nextgroup=@shSpecialNoZS,shSpecialStart |
| 680 | syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList nextgroup=@shSpecialNoZS,shSpecialStart |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 681 | endif |
| 682 | |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 683 | " ksh: ${.sh.*} variables: {{{1 |
| 684 | " ======================================== |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 685 | if exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 686 | syn match shDerefVar contained "\.\+" nextgroup=@shDerefVarList |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 687 | syn region shDeref matchgroup=PreProc start="\${\ze[\.]" end="}" contains=@shDerefVarList,shDerefPSR,shDerefPPS |
Bram Moolenaar | 6ba83ba | 2022-06-12 22:15:57 +0100 | [diff] [blame] | 688 | endif |
| 689 | |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 690 | " ksh: ${!var[*]} array index list syntax: {{{1 |
| 691 | " ======================================== |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 692 | if (exists("b:is_kornshell") && !exists("b:is_ksh88")) || exists("b:is_posix") |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 693 | syn region shDeref matchgroup=PreProc start="\${!" end="}" contains=@shDerefVarArray |
| 694 | endif |
| 695 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 696 | " bash: ${!prefix*} and ${#parameter}: {{{1 |
| 697 | " ==================================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 698 | if exists("b:is_bash") |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 699 | syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOffset |
Bram Moolenaar | bc8801c | 2016-08-02 21:04:33 +0200 | [diff] [blame] | 700 | syn match shDerefVar contained "{\@<=!\h\w*" nextgroup=@shDerefVarList |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 701 | endif |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 702 | if (exists("b:is_kornshell") && !exists("b:is_ksh88")) |
Bram Moolenaar | bc8801c | 2016-08-02 21:04:33 +0200 | [diff] [blame] | 703 | syn match shDerefVar contained "{\@<=!\h\w*[[:alnum:]_.]*" nextgroup=@shDerefVarList |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 704 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 705 | |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 706 | syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOffset,shDerefOpError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 707 | syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp |
Bram Moolenaar | bc8801c | 2016-08-02 21:04:33 +0200 | [diff] [blame] | 708 | syn match shDerefVar contained "{\@<=\h\w*" nextgroup=@shDerefVarList |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 709 | syn match shDerefVar contained '\d' nextgroup=@shDerefVarList |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 710 | if exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | bc8801c | 2016-08-02 21:04:33 +0200 | [diff] [blame] | 711 | syn match shDerefVar contained "{\@<=\h\w*[[:alnum:]_.]*" nextgroup=@shDerefVarList |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 712 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 713 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 714 | " sh ksh bash : ${var[... ]...} array reference: {{{1 |
Lucien Grondin | ce3b013 | 2023-11-04 09:41:37 +0100 | [diff] [blame] | 715 | syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError,shDerefOffset |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 716 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 717 | " Special ${parameter OPERATOR word} handling: {{{1 |
Bram Moolenaar | e271909 | 2015-01-10 15:09:25 +0100 | [diff] [blame] | 718 | " sh ksh bash : ${parameter:-word} word is default value |
| 719 | " sh ksh bash : ${parameter:=word} assign word as default value |
| 720 | " sh ksh bash : ${parameter:?word} display word if parameter is null |
| 721 | " sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing |
| 722 | " ksh bash : ${parameter#pattern} remove small left pattern |
| 723 | " ksh bash : ${parameter##pattern} remove large left pattern |
| 724 | " ksh bash : ${parameter%pattern} remove small right pattern |
| 725 | " ksh bash : ${parameter%%pattern} remove large right pattern |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 726 | " ksh bash : ${parameter^pattern} Case modification |
| 727 | " ksh bash : ${parameter^^pattern} Case modification |
| 728 | " ksh bash : ${parameter,pattern} Case modification |
| 729 | " ksh bash : ${parameter,,pattern} Case modification |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 730 | " bash : ${@:start:qty} display command line arguments from start to start+qty-1 (inferred) |
Bram Moolenaar | dd60c36 | 2023-02-27 15:49:53 +0000 | [diff] [blame] | 731 | " bash : ${parameter@operator} transforms parameter (operator∈[uULqEPARa]) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 732 | syn cluster shDerefPatternList contains=shDerefPattern,shDerefString |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 733 | if !exists("g:sh_no_error") |
| 734 | syn match shDerefOpError contained ":[[:punct:]]" |
| 735 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 736 | syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList |
| 737 | syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 738 | if exists("b:is_bash") || exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | e4a3bcf | 2016-08-26 19:52:37 +0200 | [diff] [blame] | 739 | syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList |
| 740 | syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 741 | syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern skipnl |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 742 | syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 743 | " Match parametric bracket expressions with a leading whitespace character. |
| 744 | syn region shDerefPattern contained matchgroup=shBracketExprDelim start="\[" end="\]" contains=@shBracketExprList,shDoubleQuote nextgroup=shDerefPattern |
| 745 | call s:GenerateBracketExpressionItems({'itemGroup': 'shDerefPattern', 'bracketGroup': 'shBracketExprDelim', 'extraArgs': 'contained nextgroup=shDerefPattern'}) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 746 | syn match shDerefEscape contained '\%(\\\\\)*\\.' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 747 | endif |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 748 | if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88") && !exists("b:is_mksh") && !exists("b:is_ksh93u") && !exists("b:is_ksh2020")) |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 749 | syn match shDerefOp contained "[,^]\{1,2}" nextgroup=@shDerefPatternList |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 750 | endif |
| 751 | if exists("b:is_bash") |
Bram Moolenaar | dd60c36 | 2023-02-27 15:49:53 +0000 | [diff] [blame] | 752 | syn match shDerefOp contained "@[uULQEPAKa]" |
Bram Moolenaar | d960d76 | 2011-09-21 19:22:10 +0200 | [diff] [blame] | 753 | endif |
Doug Kearns | fe22867 | 2025-05-05 20:10:11 +0200 | [diff] [blame] | 754 | syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ |
Bram Moolenaar | 4b22cdb | 2010-08-02 22:12:46 +0200 | [diff] [blame] | 755 | syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 756 | syn match shDerefString contained "\\["']" nextgroup=shDerefPattern |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 757 | |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 758 | if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88")) || exists("b:is_posix") |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 759 | " bash ksh posix : ${parameter:offset} |
| 760 | " bash ksh posix : ${parameter:offset:length} |
| 761 | syn region shDerefOffset contained start=':[^-=?+]' end='\ze:' end='\ze}' contains=shDeref,shDerefSimple,shDerefEscape nextgroup=shDerefLen,shDeref,shDerefSimple |
| 762 | syn region shDerefOffset contained start=':\s-' end='\ze:' end='\ze}' contains=shDeref,shDerefSimple,shDerefEscape nextgroup=shDerefLen,shDeref,shDerefSimple |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 763 | syn match shDerefLen contained ":[^}]\+" contains=shDeref,shDerefSimple,shArithmetic |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 764 | endif |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 765 | |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 766 | if exists("b:is_bash") || (exists("b:is_kornshell") && !exists("b:is_ksh88")) |
| 767 | " bash ksh : ${parameter/pattern/string} |
| 768 | " bash ksh : ${parameter//pattern/string} |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 769 | syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 770 | syn region shDerefPPSleft contained start='.' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' end='"' nextgroup=shDerefPPSright contains=@shPPSLeftList |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 771 | syn region shDerefPPSright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}' contains=@shPPSRightList |
Bram Moolenaar | acb4f22 | 2016-01-10 15:59:26 +0100 | [diff] [blame] | 772 | |
Johnothan King | b0691b4 | 2025-05-21 21:21:14 +0200 | [diff] [blame] | 773 | " bash ksh : ${parameter/#pattern/string} |
| 774 | " bash ksh : ${parameter/%pattern/string} |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 775 | syn match shDerefPSR contained '/[#%]' nextgroup=shDerefPSRleft,shDoubleQuote,shSingleQuote |
| 776 | syn region shDerefPSRleft contained start='[^"']' skip=@\%(\\\\\)*\\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPSRright contains=shBracketExpr |
Bram Moolenaar | acb4f22 | 2016-01-10 15:59:26 +0100 | [diff] [blame] | 777 | syn region shDerefPSRright contained start='.' skip=@\%(\\\\\)\+@ end='\ze}' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 778 | endif |
| 779 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 780 | " Arithmetic Parenthesized Expressions: {{{1 |
Bram Moolenaar | bc488a7 | 2013-07-05 21:01:22 +0200 | [diff] [blame] | 781 | "syn region shParen matchgroup=shArithRegion start='[^$]\zs(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList |
| 782 | syn region shParen matchgroup=shArithRegion start='\$\@!(\%(\ze[^(]\|$\)' end=')' contains=@shArithParenList |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 783 | |
Bram Moolenaar | 93a1df2 | 2018-09-10 11:51:50 +0200 | [diff] [blame] | 784 | " Additional sh Keywords: {{{1 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 785 | " =================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 786 | syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait |
| 787 | syn keyword shConditional contained elif else then |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 788 | if !exists("g:sh_no_error") |
| 789 | syn keyword shCondError elif else then |
| 790 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 791 | |
Bram Moolenaar | 93a1df2 | 2018-09-10 11:51:50 +0200 | [diff] [blame] | 792 | " Additional ksh Keywords and Aliases: {{{1 |
| 793 | " =================================== |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 794 | if exists("b:is_kornshell") || exists("b:is_posix") |
| 795 | syn keyword shStatement bg builtin disown enum export false fg getconf getopts hist jobs let printf sleep true unalias whence |
| 796 | syn keyword shStatement typeset skipwhite nextgroup=shSetOption |
Bram Moolenaar | 93a1df2 | 2018-09-10 11:51:50 +0200 | [diff] [blame] | 797 | syn keyword shStatement autoload compound fc float functions hash history integer nameref nohup r redirect source stop suspend times type |
Bram Moolenaar | 690afe1 | 2017-01-28 18:34:47 +0100 | [diff] [blame] | 798 | if exists("b:is_posix") |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 799 | syn keyword shStatement command |
| 800 | else |
| 801 | syn keyword shStatement time |
| 802 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 803 | |
Bram Moolenaar | 93a1df2 | 2018-09-10 11:51:50 +0200 | [diff] [blame] | 804 | " Additional bash Keywords: {{{1 |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 805 | " ===================== |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 806 | elseif exists("b:is_bash") |
Eisuke Kawashima | 54cb514 | 2025-01-18 10:11:28 +0100 | [diff] [blame] | 807 | syn keyword shStatement bg builtin disown export false fg getopts jobs let printf true unalias |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 808 | syn keyword shStatement typeset nextgroup=shSetOption |
| 809 | syn keyword shStatement fc hash history source suspend times type |
Eisuke Kawashima | 54cb514 | 2025-01-18 10:11:28 +0100 | [diff] [blame] | 810 | syn keyword shStatement bind caller compopt declare dirs enable help logout local mapfile popd pushd readarray shopt typeset |
Bram Moolenaar | b730f0c | 2018-11-25 03:56:26 +0100 | [diff] [blame] | 811 | else |
| 812 | syn keyword shStatement login newgrp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 813 | endif |
| 814 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 815 | " Synchronization: {{{1 |
| 816 | " ================ |
Bram Moolenaar | 03413f4 | 2016-04-12 21:07:15 +0200 | [diff] [blame] | 817 | if !exists("g:sh_minlines") |
| 818 | let s:sh_minlines = 200 |
| 819 | else |
| 820 | let s:sh_minlines= g:sh_minlines |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 821 | endif |
Bram Moolenaar | 03413f4 | 2016-04-12 21:07:15 +0200 | [diff] [blame] | 822 | if !exists("g:sh_maxlines") |
| 823 | let s:sh_maxlines = 2*s:sh_minlines |
| 824 | if s:sh_maxlines < 25 |
| 825 | let s:sh_maxlines= 25 |
| 826 | endif |
| 827 | else |
| 828 | let s:sh_maxlines= g:sh_maxlines |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 829 | endif |
Bram Moolenaar | 03413f4 | 2016-04-12 21:07:15 +0200 | [diff] [blame] | 830 | exec "syn sync minlines=" . s:sh_minlines . " maxlines=" . s:sh_maxlines |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 831 | syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>" |
| 832 | syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>" |
| 833 | syn sync match shDoSync grouphere shDo "\<do\>" |
| 834 | syn sync match shDoSync groupthere shDo "\<done\>" |
| 835 | syn sync match shForSync grouphere shFor "\<for\>" |
| 836 | syn sync match shForSync groupthere shFor "\<in\>" |
| 837 | syn sync match shIfSync grouphere shIf "\<if\>" |
| 838 | syn sync match shIfSync groupthere shIf "\<fi\>" |
| 839 | syn sync match shUntilSync grouphere shRepeat "\<until\>" |
| 840 | syn sync match shWhileSync grouphere shRepeat "\<while\>" |
| 841 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 842 | " Default Highlighting: {{{1 |
| 843 | " ===================== |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 844 | if !exists("skip_sh_syntax_inits") |
| 845 | hi def link shArithRegion shShellVariables |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 846 | hi def link shArrayValue shDeref |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 847 | hi def link shAstQuote shDoubleQuote |
| 848 | hi def link shAtExpr shSetList |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 849 | hi def link shBkslshSnglQuote shSingleQuote |
| 850 | hi def link shBkslshDblQuote shDOubleQuote |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 851 | hi def link shBeginHere shRedir |
| 852 | hi def link shCaseBar shConditional |
| 853 | hi def link shCaseCommandSub shCommandSub |
| 854 | hi def link shCaseDoubleQuote shDoubleQuote |
| 855 | hi def link shCaseIn shConditional |
| 856 | hi def link shQuote shOperator |
| 857 | hi def link shCaseSingleQuote shSingleQuote |
| 858 | hi def link shCaseStart shConditional |
| 859 | hi def link shCmdSubRegion shShellVariables |
| 860 | hi def link shColon shComment |
| 861 | hi def link shDerefOp shOperator |
| 862 | hi def link shDerefPOL shDerefOp |
| 863 | hi def link shDerefPPS shDerefOp |
| 864 | hi def link shDerefPSR shDerefOp |
| 865 | hi def link shDeref shShellVariables |
| 866 | hi def link shDerefDelim shOperator |
| 867 | hi def link shDerefSimple shDeref |
| 868 | hi def link shDerefSpecial shDeref |
| 869 | hi def link shDerefString shDoubleQuote |
| 870 | hi def link shDerefVar shDeref |
| 871 | hi def link shDoubleQuote shString |
| 872 | hi def link shEcho shString |
| 873 | hi def link shEchoDelim shOperator |
| 874 | hi def link shEchoQuote shString |
| 875 | hi def link shForPP shLoop |
| 876 | hi def link shFunction Function |
| 877 | hi def link shEmbeddedEcho shString |
| 878 | hi def link shEscape shCommandSub |
| 879 | hi def link shExDoubleQuote shDoubleQuote |
| 880 | hi def link shExSingleQuote shSingleQuote |
| 881 | hi def link shHereDoc shString |
| 882 | hi def link shHereString shRedir |
| 883 | hi def link shHerePayload shHereDoc |
| 884 | hi def link shLoop shStatement |
| 885 | hi def link shSpecialNxt shSpecial |
| 886 | hi def link shNoQuote shDoubleQuote |
| 887 | hi def link shOption shCommandSub |
| 888 | hi def link shPattern shString |
| 889 | hi def link shParen shArithmetic |
| 890 | hi def link shPosnParm shShellVariables |
| 891 | hi def link shQuickComment shComment |
Bram Moolenaar | 93a1df2 | 2018-09-10 11:51:50 +0200 | [diff] [blame] | 892 | hi def link shBQComment shComment |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 893 | hi def link shRange shOperator |
| 894 | hi def link shRedir shOperator |
| 895 | hi def link shSetListDelim shOperator |
| 896 | hi def link shSetOption shOption |
| 897 | hi def link shSingleQuote shString |
| 898 | hi def link shSource shOperator |
| 899 | hi def link shStringSpecial shSpecial |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 900 | hi def link shSpecialStart shSpecial |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 901 | hi def link shSubShRegion shOperator |
| 902 | hi def link shTestOpr shConditional |
| 903 | hi def link shTestPattern shString |
| 904 | hi def link shTestDoubleQuote shString |
| 905 | hi def link shTestSingleQuote shString |
| 906 | hi def link shTouchCmd shStatement |
| 907 | hi def link shVariable shSetList |
| 908 | hi def link shWrapLineOperator shOperator |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 909 | |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 910 | if exists("b:is_bash") |
| 911 | hi def link bashAdminStatement shStatement |
| 912 | hi def link bashSpecialVariables shShellVariables |
| 913 | hi def link bashStatement shStatement |
| 914 | hi def link shCharClass shSpecial |
Bram Moolenaar | d58a3bf | 2020-09-28 21:48:16 +0200 | [diff] [blame] | 915 | hi def link shDerefOffset shDerefOp |
| 916 | hi def link shDerefLen shDerefOffset |
Bram Moolenaar | 6be7f87 | 2012-01-20 21:08:56 +0100 | [diff] [blame] | 917 | endif |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 918 | if exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 919 | hi def link kshSpecialVariables shShellVariables |
| 920 | hi def link kshStatement shStatement |
| 921 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 922 | |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 923 | if !exists("g:sh_no_error") |
| 924 | hi def link shCaseError Error |
| 925 | hi def link shCondError Error |
| 926 | hi def link shCurlyError Error |
| 927 | hi def link shDerefOpError Error |
| 928 | hi def link shDerefWordError Error |
| 929 | hi def link shDoError Error |
| 930 | hi def link shEsacError Error |
| 931 | hi def link shIfError Error |
| 932 | hi def link shInError Error |
| 933 | hi def link shParenError Error |
| 934 | hi def link shTestError Error |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 935 | if exists("b:is_kornshell") || exists("b:is_posix") |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 936 | hi def link shDTestError Error |
| 937 | endif |
| 938 | endif |
| 939 | |
| 940 | hi def link shArithmetic Special |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 941 | hi def link shBracketExprDelim Delimiter |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 942 | hi def link shCharClass Identifier |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 943 | hi def link shCollSymb shCharClass |
| 944 | hi def link shEqClass shCharClass |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 945 | hi def link shSnglCase Statement |
| 946 | hi def link shCommandSub Special |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 947 | hi def link shCommandSubBQ shCommandSub |
Johnothan King | add31ba | 2024-01-22 11:19:54 -0800 | [diff] [blame] | 948 | hi def link shSubshare shCommandSub |
| 949 | hi def link shValsub shCommandSub |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 950 | hi def link shComment Comment |
| 951 | hi def link shConditional Conditional |
| 952 | hi def link shCtrlSeq Special |
| 953 | hi def link shExprRegion Delimiter |
| 954 | hi def link shFunctionKey Function |
| 955 | hi def link shFunctionName Function |
| 956 | hi def link shNumber Number |
| 957 | hi def link shOperator Operator |
| 958 | hi def link shRepeat Repeat |
| 959 | hi def link shSet Statement |
| 960 | hi def link shSetList Identifier |
| 961 | hi def link shShellVariables PreProc |
| 962 | hi def link shSpecial Special |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 963 | hi def link shSpecialDQ Special |
| 964 | hi def link shSpecialSQ Special |
Bram Moolenaar | b0d45e7 | 2017-11-05 18:19:24 +0100 | [diff] [blame] | 965 | hi def link shSpecialNoZS shSpecial |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 966 | hi def link shStatement Statement |
| 967 | hi def link shString String |
| 968 | hi def link shTodo Todo |
| 969 | hi def link shAlias Identifier |
| 970 | hi def link shHereDoc01 shRedir |
| 971 | hi def link shHereDoc02 shRedir |
| 972 | hi def link shHereDoc03 shRedir |
| 973 | hi def link shHereDoc04 shRedir |
| 974 | hi def link shHereDoc05 shRedir |
| 975 | hi def link shHereDoc06 shRedir |
| 976 | hi def link shHereDoc07 shRedir |
| 977 | hi def link shHereDoc08 shRedir |
| 978 | hi def link shHereDoc09 shRedir |
| 979 | hi def link shHereDoc10 shRedir |
| 980 | hi def link shHereDoc11 shRedir |
| 981 | hi def link shHereDoc12 shRedir |
| 982 | hi def link shHereDoc13 shRedir |
| 983 | hi def link shHereDoc14 shRedir |
| 984 | hi def link shHereDoc15 shRedir |
Bram Moolenaar | 23515b4 | 2020-11-29 14:36:24 +0100 | [diff] [blame] | 985 | hi def link shHereDoc16 shRedir |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 986 | endif |
Bram Moolenaar | b4ff518 | 2015-11-10 21:15:48 +0100 | [diff] [blame] | 987 | |
| 988 | " Delete shell folding commands {{{1 |
| 989 | " ============================= |
| 990 | delc ShFoldFunctions |
| 991 | delc ShFoldHereDoc |
| 992 | delc ShFoldIfDoFor |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 993 | |
Aliaksei Budavei | 48fa319 | 2024-12-30 10:23:50 +0100 | [diff] [blame] | 994 | " Delete the bracket expression function {{{1 |
| 995 | " ====================================== |
| 996 | delfun s:GenerateBracketExpressionItems |
| 997 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 998 | " Set Current Syntax: {{{1 |
| 999 | " =================== |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1000 | if exists("b:is_bash") |
| 1001 | let b:current_syntax = "bash" |
| 1002 | elseif exists("b:is_kornshell") |
| 1003 | let b:current_syntax = "ksh" |
Bram Moolenaar | 51ad4ea | 2018-04-06 11:14:11 +0200 | [diff] [blame] | 1004 | elseif exists("b:is_posix") |
| 1005 | let b:current_syntax = "posix" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1006 | else |
| 1007 | let b:current_syntax = "sh" |
| 1008 | endif |
| 1009 | |
Bram Moolenaar | d4755bb | 2004-09-02 19:12:26 +0000 | [diff] [blame] | 1010 | " vim: ts=16 fdm=marker |