rcshell.vim (11655B)
1 " Vim syntax file 2 " Language: rc 3 " Maintainer: Jakukyo Friel <weakish@gmail.com> 4 " Last Change: Dec 28 2014 5 " License: This file is placed in the public domain. 6 7 "Credits 8 """"""""""""" 9 " Most of the work is done by Andy Spencer. 10 " [Jakukyo Friel has] only made some minor changes: 11 " * make this syntax highlight works with Byron Rakitzis' reimplementation. 12 " * edit rcHereDoc match pattern to get <<EOF >output highlighted correctly. 13 " -- weakish 14 " 15 " Also edited by hhvn for the following: 16 " - allow syntax to be loaded for multiple files 17 " - support ``ifs-list{cmd} from Rakitzis' rc, and `ifs-list{cmd} from 18 " the rc-line-split patch (found in 9front). ``{cmd} however is an error 19 " - return anywhere in a function (allowed by Rakitzis' rc) 20 " - signal names are only highlighted like so 'fn <signal here> {' rather 21 " than inside the function body 22 " - more such signal names, aswell as the prompt (invoked by Rakitzis's rc 23 " before $prompt(1) is printed) and beforecmd (invoked by my fork before 24 " any command is run. 25 " 26 "Info 27 """""""""" 28 " 29 " This syntax file works with both Byron Rakitzis' reimplementation and 30 " plan9port's implementation. 31 " There is a tradeoff: less powerful `(ba)sh like substitution` syntax 32 " error detection. 33 34 if version < 600 35 syntax clear 36 elseif exists("b:current_syntax") 37 finish 38 endif 39 40 " I'm lazy, if someone knows how to do proper syncing, they can fix this 41 " Rc script should be small anyway.. 42 syn sync fromstart 43 44 45 " Based on the sections of rc(1) 46 47 "Top levels 48 """"""""""" 49 " Ignore valid start/ends for now 50 " List = top level 51 syn cluster rcList contains=@rcSimple,@rcArgument,@rcRedirect,@rcCompound 52 53 "Command Lines 54 """""""""""""" 55 syn cluster rcSimple contains=rcTermin,rcContinue,rcComment 56 57 syn match rcTermin "[;&]" 58 syn match rcContinue "\\$" 59 syn match rcComment "#.*" 60 61 62 "Arguments and Variables 63 """""""""""""""""""""""" 64 " Arguments should be proceeded by additional arguments, not commands, etc 65 syn cluster rcArgument contains=@rcBuiltins,@rcArgument2 66 syn cluster rcArgument2 contains=rcWord,@rcSimple,rcNumber,rcPattern,rcQuoted,rcSubQuote,rcParens,rcVar,rcSubst,rcSubstIFS,rcSub,rcJoin 67 68 syn match rcWord "[^#;&|^$=`'{}()<>\[\] \t\r]" skipwhite nextgroup=@rcArgument2 69 70 71 syn match rcNumber "\<\d\+\>" skipwhite nextgroup=@rcArgument2 72 73 syn match rcPattern "[*?]" skipwhite nextgroup=@rcArgument2 74 syn region rcPattern matchgroup=rcOperator start="\[" skip="\\\]" end="\]" skipwhite nextgroup=@rcArgument2 keepend contains=rcPatternBdy, 75 syn match rcPatternBdy ".*" contained contains=rcPatternKey 76 syn match rcPatternKey "\[\@<=\~\|[^\[]\zs-\ze[^\]]" contained " ? and - in [?..] [a-c] 77 78 syn region rcQuoted matchgroup=rcQuoted start="'" skip="''" end="'" skipwhite nextgroup=@rcArgument2 contains=rcQuote 79 syn match rcQuote "''" contained 80 81 syn region rcParens matchgroup=rcOperator start="(" end=")" skipwhite nextgroup=@rcArgument2 contains=@rcArgument 82 83 syn match rcVar "\$[^ \t(]\w*" skipwhite nextgroup=rcVarList,@rcArgument2 contains=rcVarSpecial 84 syn match rcVar "\$[#"^]\S\w*\ze[^(]" skipwhite nextgroup=@rcArgument2 contains=rcVarOper,rcVarSPecial 85 syn region rcVarList matchgroup=rcIdentifier start="(" end=")" skipwhite nextgroup=@rcArgument2 contains=@rcArgument contained 86 syn match rcVarOper +[#"^]+ contained 87 syn match rcVarSpecial "\v\$?<(home|ifs|path|pid|prompt|status|contained)>" contained 88 " Todo: Make error for $"foo( 89 90 syn region rcSubst matchgroup=rcInclude start="[<>]{" end="}" skipwhite nextgroup=@rcArgument2 contains=@rcList 91 syn region rcSubstIFS matchgroup=rcInclude start="``\|`" end="{"me=s-1 skipwhite nextgroup=rcSubstBrace contains=@rcList 92 syn region rcSubstBrace matchgroup=rcInclude start="{" end="}" skipwhite nextgroup=@rcArgument2 contained contains=@rcList 93 syn match rcSub "`\<\S\+\>" 94 syn match rcJoin "\^" skipwhite nextgroup=@rcArgument2 contains=rcError 95 syn match rcError "\v(^|\^)\s*\^|\^\ze\s*($|#|;|\^)" skipwhite nextgroup=@rcArgument2 96 " Todo: Error on ^$ 97 98 99 "I/O Redirection 100 """""""""""""""" 101 syn cluster rcRedirect contains=rcRedir,rcHereDoc 102 103 syn match rcRedir "[<>]\v(\[\d+\=?\d*])?\ze([^{]|$)" skipwhite nextgroup=@rcArgument contains=rcNumber 104 syn match rcRedir ">>" skipwhite nextgroup=@rcArgument 105 106 syn region rcHereDoc matchgroup=rcOperator start="<<\z([^<> ]\+\)" end="^\z1$" contains=rcVar 107 syn region rcHereDoc matchgroup=rcOperator start="<<'\z(.*\)'" end="^\z1$" 108 " Todo: what's with ^'s in here docs? 109 " Todo: <<'>' >output or <<' 'EOF >output still doesn't get highlighted 110 " correct, but I guess peopel are unlikely to write such scripts. 111 112 "Compound Commands 113 """""""""""""""""" 114 " Todo: What to do when only one command is accepted, e.g. while() <command> 115 syn cluster rcCompound contains=rcPipe,rcLogical,rcInverted,rcSubShell,rcIf,rcIfNot,rcElse,rcFor,rcWhile,rcSwitch,rcBrace,rcFunction,rcAssign 116 117 syn match rcPipe "|\v(\[\d+(\=\d+)?])?" contains=rcNumber 118 syn match rcLogical "\(&&\|||\)" 119 120 syn region rcIf matchgroup=rcConditional start="if\s*(" end=")" contains=@rcList 121 syn match rcIfNot "\<if\s\+not\>" 122 " Todo: error on if(..) <command> <command> if not 123 " use: matchgroup=rcIfNot end="if not"? 124 syn match rcElse "\<else\>" 125 126 syn region rcFor matchgroup=rcRepeat start="for\s*(" end=")" contains=rcForIn,@rcArgument 127 128 syn keyword rcForIn in contained 129 " Todo: for(in) 130 131 syn region rcWhile matchgroup=rcRepeat start="while\s*(" end=")" contains=@rcList 132 133 syn region rcSwitch matchgroup=rcConditional start="switch\s*(" end=")" skipwhite nextgroup=rcSwitchBody contains=@rcArgument 134 syn region rcSwitchBody matchgroup=rcConditional start="{" end="}" contains=@rcList,rcSwitchCase 135 syn keyword rcSwitchCase case contained 136 137 syn region rcBrace matchgroup=rcOperator start="{" end="}" contains=@rcList 138 139 syn match rcFunction "\v<fn\s+\w+>" contains=rcHandler skipwhite nextgroup=rcFnBody 140 syn region rcFnBody matchgroup=rcFunction start="{" end="}" contained contains=@rcList 141 syn keyword rcHandler prompt beforecmd sigexit sigabrt sigiot sigalrm sigbus sigfpe sighup sigill sigint sigpipe sigpoll sigquit sigterm sigwinch sigxcpu 142 143 syn match rcAssign "\w\+\ze\s*=" skipwhite nextgroup=@rcArgument contains=rcVarSpecial 144 145 "Built-in Commands 146 """""""""""""""""" 147 " Todo: only at the beginning of the command 148 syn cluster rcBuiltins contains=rcPrefixes,rcBuiltinMatch,rcBuiltinKeyword,coreutils,p9putils 149 syn match rcPrefixes "[!@]" 150 syn match rcBuiltinMatch skipwhite nextgroup=@rcArgument2 "[.~]" 151 syn keyword rcBuiltinKeyword skipwhite nextgroup=@rcArgument2 break builtin cd echo eval exec exit flag limit newpgrp rfork shift umask wait whatis return 152 syn keyword coreutils skipwhite nextgroup=@rcArgument2 dd cp df du ln ls mv rm tr wc cat dir cut env pwd seq tty yes date echo expr head tail sort stty sync true vdir dirname chgrp chmod chown false mkdir mknod rmdir sleep touch uname chroot mkfifo mktemp readlink basename DIR_COLORS du id nl od pr tr wc dir cut env fmt ptx seq tac tee sum tty who yes arch comm expr fold head join link nice shuf tail sort test stat uniq vdir unexpand dirname chcon cksum nohup paste pinky shred sleep split touch tsort uname users sha1sum truncate logname base64 timeout chroot csplit factor expand hostid md5sum sha224sum sha256sum mkfifo mktemp sha384sum sha512sum printf runcon stdbuf unlink whoami printenv pathchk dircolors readlink install basename 153 syn keyword p9putils skipwhite nextgroup=@rcArgument2 9 B E g p u 9a 9c 9l 9p bc cb db dc dd ed du lc mc ls mk pr ps rc rm tr wc xd 9ar 9fs awd awk cal cat bmp cmp dns eqn fmt gif hoc ico img jpg lex man pbd pic png ppm psu psv rio sam sed seq sig tar tbl tcs tee src srv sum vac web win zip yuv troff2png dnsquery Mail acid acme date comm core crop dial dict diff echo file freq grap hget grep hist gzip ipso join kill mapd look news nobs page plot read scat slay tail sort test time stop tpic tref vcat uniq vnfs yacc cmapcube secstored troff2html sftpcache delatex cleanname devdraw Getdir 9term 9660srv factotum disknfs adict ascii astro bzip2 fsize graph gview iconv idiff resample label mkdir mount mtime nroff plumb proof ramfs sleep spell split sprog stack start stats togif toico topng toppm touch troff vacfs tweak units unvac unutf unzip usage wmail netfileget netfileput doctype acidtypes htmlroff samsave samterm dsa2pub dsa2ssh secuser ndbmkhash sha1sum rsa2csr rsa2pub rsa2ssh rsafill listen1 ndbipquery ndbquery auxstats snarfer lookman tcolors Netfiles calendar aescbc codereview strings bundle colors deroff dnstcp dsagen factor fontsrv ndbmkdb fortune tr2post getflags gunzip import secstore pemdecode md5sum mk9660 pemencode netkey passwd vbackup primes psdownload unicode unmount rsagen vmount vwhois xshove acmeevent yesterday vmount0 ndbmkhosts asn12dsa asn12rsa statusbar htmlfmt netfilestat auxclog wintext rsa2x509 9pfuse readcons plumber basename 9pserve dump9660 namespace bunzip2 psfonts dnsdebug 154 155 " Misc 156 """""" 157 syn region rcSubQuote matchgroup=rcQuoted start="rc\s\+-c\s*'"hs=e-1 skip="''" end="'" skipwhite nextgroup=@rcArgument2 contains=rcQuote,@rcList 158 159 "Errors 160 """"""" 161 syn match rcError "[\]})]" 162 syn match rcError "\$(.\{-})\|\${.\{-}}\|\d\+>\(&\d\+\)\?\|`[^{]\{-}`\s\|{.*,.*}" 163 syn match rcError "``{" 164 165 " Ignore bash 166 " Bad ${}, 2>&1, `foo`, 167 " TODO: {foo,bar}.txt (use: (foo bar)^.txt 168 " {foo; bar} is ok 169 " $() is for variables 170 171 " Highlighting 172 hi def link rcTermin Operator 173 hi def link rcContinue Operator 174 hi def link rcComment Comment 175 "Arguments and Variables 176 hi def link rcNumber Number 177 hi def link rcPattern PreProc 178 hi def link rcQuoted String 179 hi def link rcQuote Delimiter 180 hi def link rcVar Identifier 181 hi def link rcVarOper SpecialChar 182 hi def link rcVarSpecial Keyword 183 hi def link rcJoin Special 184 "I/O Redirection 185 hi def link rcRedir Operator 186 hi def link rcHereDoc String 187 "Compound Commands 188 hi def link rcPipe Operator 189 hi def link rcLogical Operator 190 hi def link rcIfNot Conditional 191 hi def link rcElse Conditional 192 hi def link rcHandler Keyword 193 hi def link rcAssign Identifier 194 hi def link rcPrefixes Macro 195 "Built-in Commands 196 hi def link rcBuiltinKeyword Keyword 197 hi def link rcBuiltinMatch Keyword 198 hi def link coreutils Keyword 199 hi def link p9putils Keyword 200 201 " Ends of regions 202 hi def link rcIdentifier Identifier 203 hi def link rcPreProc PreProc 204 hi def link rcInclude Include 205 hi def link rcSub Include 206 hi def link rcKeyword Keyword 207 hi def link rcOperator Operator 208 hi def link rcRepeat Repeat 209 hi def link rcConditional Conditional 210 hi def link rcFunction Function 211 212 " Specials inside regions 213 hi def link rcForIn Keyword 214 hi def link rcSwitchCase Label 215 hi def link rcPatternKey SpecialChar 216 217 " Errors 218 hi def link rcError Error 219 220 let b:current_syntax = "rc"