home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / syntax / sh.vim < prev    next >
Encoding:
Text File  |  2003-05-11  |  26.5 KB  |  501 lines

  1. " Vim syntax file
  2. " Language:              shell (sh) Korn shell (ksh) bash (sh)
  3. " Maintainer:              Dr. Charles E. Campbell, Jr. <Charles.E.Campbell.1@nasa.gov>
  4. " Previous Maintainer:          Lennart Schultz <Lennart.Schultz@ecmwf.int>
  5. " Last Change:              Apr 09, 2003
  6. " Version:              57
  7. " URL:           http://www.erols.com/astronaut/vim/index.html#vimlinks_syntax
  8. "
  9. " Using the following VIM variables:
  10. " b:is_kornshell           if defined, enhance with kornshell syntax
  11. " b:is_bash               if defined, enhance with bash syntax
  12. "   is_kornshell           if neither b:is_kornshell or b:is_bash is
  13. "                  defined, then if is_kornshell is set
  14. "                  b:is_kornshell is default
  15. "   is_bash               if none of the previous three variables are
  16. "                  defined, then if is_bash is set b:is_bash is default
  17. " g:sh_fold_enabled           if non-zero, syntax folding is enabled
  18. "
  19. " This file includes many ideas from â•”ric Brunet (eric.brunet@ens.fr)
  20.  
  21. " For version 5.x: Clear all syntax items
  22. " For version 6.x: Quit when a syntax file was already loaded
  23. if version < 600
  24.   syntax clear
  25. elseif exists("b:current_syntax")
  26.   finish
  27. endif
  28.  
  29. " b:is_sh is set when "#! /bin/sh" is found;
  30. " However, it often is just a masquerade by bash (typically Linux)
  31. " or kornshell (typically workstations with Posix "sh").
  32. " So, when the user sets "is_bash" or "is_kornshell",
  33. " a b:is_sh is converted into b:is_bash/b:is_kornshell,
  34. " respectively.
  35. if !exists("b:is_kornshell") && !exists("b:is_bash")
  36.   if exists("is_kornshell")
  37.     let b:is_kornshell= 1
  38.     if exists("b:is_sh")
  39.       unlet b:is_sh
  40.     endif
  41.   elseif exists("is_bash")
  42.     let b:is_bash= 1
  43.     if exists("b:is_sh")
  44.       unlet b:is_sh
  45.     endif
  46.   else
  47.     let b:is_sh= 1
  48.   endif
  49. endif
  50.  
  51. if !exists("g:sh_fold_enabled")
  52.  let g:sh_fold_enabled= 0
  53. endif
  54.  
  55. " sh syntax is case sensitive
  56. syn case match
  57. setlocal isk+=.
  58.  
  59. " Clusters: contains=@... clusters
  60. "==================================
  61. syn cluster shCaseEsacList    contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseSingleQuote,shCaseDoubleQuote,shSpecial
  62. syn cluster shCommandSubList1 contains=shArithmetic,shDeref,shDerefSimple,shNumber,shPosnParm,shSpecial,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh
  63. syn cluster shCommandSubList2 contains=@shCommandSubList1
  64. syn cluster shDblQuoteList    contains=shCommandSub,shDeref,shDerefSimple,shSpecial,shPosnParm
  65. syn cluster shDerefList          contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError
  66. syn cluster shDerefVarList    contains=shDerefOp,shDerefVarArray,shDerefOpError
  67. syn cluster shIdList          contains=shCommandSub,shWrapLineOperator,shIdWhiteSpace,shDeref,shDerefSimple,shSpecial,shRedir,shSingleQuote,shDoubleQuote
  68. syn cluster shCaseList          contains=@shCommandSubList1,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,bkshFunction,shSpecial
  69. syn cluster shColonList          contains=@shCaseList
  70. syn cluster shEchoList          contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shSingleQuote,shDoubleQuote,shSpecial
  71. syn cluster shExprList1          contains=shCharClass,shNumber,shOperator,shSingleQuote,shDoubleQuote,shSpecial,shExpr,shDblBrace,shDeref,shDerefSimple
  72. syn cluster shExprList2          contains=@shExprList1,@shCaseList
  73. syn cluster shLoopList          contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac
  74. syn cluster shSubShList          contains=@shCaseList
  75. syn cluster shTestList          contains=shCharClass,shComment,shDeref,shDerefSimple,shDoubleQuote,shExpr,shExpr,shNumber,shOperator,shSingleQuote,shSpecial,shTestOpr
  76. syn cluster shFunctionList    contains=@shCaseList,shOperator
  77.  
  78. " Echo:
  79. " ====
  80. " This one is needed INSIDE a CommandSub, so that `echo bla` be correct
  81. syn region shEcho matchgroup=shStatement start="\<echo\>"  skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList
  82. syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList
  83.  
  84. " This must be after the strings, so that bla \" be correct
  85. syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=shNumber,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shSpecial,shOperator,shDoubleQuote,shCharClass
  86.  
  87. " Error Codes
  88. " ===========
  89. syn match   shDoError "\<done\>"
  90. syn match   shIfError "\<fi\>"
  91. syn match   shInError "\<in\>"
  92. syn match   shCaseError ";;"
  93. syn match   shEsacError "\<esac\>"
  94. syn match   shCurlyError "}"
  95. syn match   shParenError ")"
  96. if exists("b:is_kornshell")
  97.  syn match     shDTestError "]]"
  98. endif
  99. syn match     shTestError "]"
  100.  
  101. " Options interceptor
  102. " ===================
  103. syn match   shOption  "\s[\-+][a-zA-Z0-9]\+\>"ms=s+1
  104. syn match   shOption  "\s--\S\+"ms=s+1
  105.  
  106. " Operators:
  107. " =========
  108. syn match   shOperator                 "[!&;|]"
  109. syn match   shOperator                 "\[[[^:]\|\]]"
  110. syn match   shOperator                 "!\=="               skipwhite nextgroup=shPattern
  111. syn match   shPattern          contained         "\<\S\+\())\)\@="           contains=shSingleQuote,shDoubleQuote,shDeref
  112.  
  113. " Subshells:
  114. " =========
  115. syn region shExpr  transparent matchgroup=shExprRegion  start="{" end="}"          contains=@shExprList2
  116. syn region shSubSh transparent matchgroup=shSubShRegion start="(" end=")"          contains=@shSubShList
  117.  
  118. " Tests
  119. "======
  120. syn region  shExpr transparent matchgroup=shRange start="\[" skip=+\\\\\|\\$+ end="\]" contains=@shTestList
  121. syn region  shExpr transparent matchgroup=shStatement start="\<test\>" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1
  122. syn match   shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!=<>]"
  123. if exists("b:is_kornshell") || exists("b:is_bash")
  124.  syn region  shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]"      contains=@shTestList
  125.  syn region  shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))"      contains=@shTestList
  126. endif
  127.  
  128. " Character Class in Range
  129. " ========================
  130. syn match   shCharClass          contained         "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
  131.  
  132. " Loops: do, if, while, until
  133. " =====
  134. syn region shDo  transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
  135. syn region shIf  transparent matchgroup=shConditional start="\<if\>" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>"   contains=@shLoopList,shDblBrace,shDblParen
  136. syn region shFor matchgroup=shLoop start="\<for\>" end="\<in\>" end="\<do\>"me=e-2      contains=@shLoopList,shDblParen
  137. if exists("b:is_kornshell") || exists("b:is_bash")
  138.  syn cluster shCaseList add=shRepeat
  139.  syn region shRepeat   matchgroup=shLoop   start="\<while\>" end="\<in\>" end="\<do\>"me=e-2         contains=@shLoopList,shDblParen,shDblBrace
  140.  syn region shRepeat   matchgroup=shLoop   start="\<until\>" end="\<in\>" end="\<do\>"me=e-2         contains=@shLoopList,shDblParen,shDblBrace
  141.  syn region shCaseEsac matchgroup=shConditional start="\<select\>" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
  142. else
  143.  syn region shRepeat   matchgroup=shLoop   start="\<while\>" end="\<do\>"me=e-2          contains=@shLoopList
  144.  syn region shRepeat   matchgroup=shLoop   start="\<until\>" end="\<do\>"me=e-2          contains=@shLoopList
  145. endif
  146.  
  147. " Case: case...esac
  148. " ====
  149. syn match   shCaseBar          contained skipwhite "[^|"`'()]\{-}|"hs=e              nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseSingleQuote,shCaseDoubleQuote
  150. syn match   shCaseStart          contained skipwhite skipnl "("                  nextgroup=shCase,shCaseBar
  151. syn region  shCase          contained skipwhite skipnl matchgroup=shSnglCase start="[^$()]\{-})"ms=s,hs=e  end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,,shComment
  152. syn region  shCaseEsac          matchgroup=shConditional start="\<case\>" end="\<esac\>"      contains=@shCaseEsacList
  153. syn keyword shCaseIn          contained skipwhite skipnl in                  nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseSingleQuote,shCaseDoubleQuote
  154. syn region  shCaseSingleQuote matchgroup=shOperator start=+'+ skip=+\\\\\|\\.+ end=+'+      contains=shStringSpecial               skipwhite skipnl nextgroup=shCaseBar        contained
  155. syn region  shCaseDoubleQuote matchgroup=shOperator start=+"+ skip=+\\\\\|\\.+ end=+"+      contains=@shDblQuoteList,shStringSpecial     skipwhite skipnl nextgroup=shCaseBar        contained
  156. syn region  shCaseCommandSub  start=+`+ skip=+\\\\\|\\.+ end=+`+              contains=@shCommandSubList1               skipwhite skipnl nextgroup=shCaseBar        contained
  157.  
  158. " Misc
  159. "=====
  160. syn match   shWrapLineOperator "\\$"
  161. syn region  shCommandSub   start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList1
  162.  
  163. " $(..) is not supported by sh (Bourne shell).  However, apparently
  164. " some systems (HP?) have as their /bin/sh a (link to) Korn shell
  165. " (ie. Posix compliant shell).  /bin/ksh should work for those
  166. " systems too, however, so the following syntax will flag $(..) as
  167. " an Error under /bin/sh.  By consensus of vimdev'ers!
  168. if exists("b:is_kornshell") || exists("b:is_bash")
  169.  syn region shCommandSub matchgroup=shCmdSubRegion start="\$("  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList2
  170.  syn region shArithmetic matchgroup=shArithRegion  start="\$((" skip='\\\\\|\\.' end="))" contains=@shCommandSubList2
  171.  syn match  shSkipInitWS contained         "^\s\+"
  172. else
  173.  syn region shCommandSub matchgroup=Error start="$(" end=")" contains=@shCommandSubList2
  174. endif
  175.  
  176. if exists("b:is_bash")
  177.  syn cluster shCommandSubList1 add=bashSpecialVariables,bashStatement
  178.  syn cluster shCaseList           add=bashAdminStatement,bashStatement
  179.  syn keyword bashSpecialVariables contained  BASH        HISTCONTROL       LANG          OPTERR     PWD
  180.  syn keyword bashSpecialVariables contained  BASH_ENV        HISTFILE       LC_ALL      OPTIND     RANDOM
  181.  syn keyword bashSpecialVariables contained  BASH_VERSINFO  HISTFILESIZE   LC_COLLATE      OSTYPE     REPLY
  182.  syn keyword bashSpecialVariables contained  BASH_VERSION   HISTIGNORE       LC_MESSAGES      PATH         SECONDS
  183.  syn keyword bashSpecialVariables contained  CDPATH        HISTSIZE       LINENO      PIPESTATUS     SHELLOPTS
  184.  syn keyword bashSpecialVariables contained  DIRSTACK        HOME       MACHTYPE      PPID         SHLVL
  185.  syn keyword bashSpecialVariables contained  EUID        HOSTFILE       MAIL          PROMPT_COMMAND TIMEFORMAT
  186.  syn keyword bashSpecialVariables contained  FCEDIT        HOSTNAME       MAILCHECK      PS1         TIMEOUT
  187.  syn keyword bashSpecialVariables contained  FIGNORE        HOSTTYPE       MAILPATH      PS2         UID
  188.  syn keyword bashSpecialVariables contained  GLOBIGNORE        IFS           OLDPWD      PS3         auto_resume
  189.  syn keyword bashSpecialVariables contained  GROUPS        IGNOREEOF       OPTARG      PS4         histchars
  190.  syn keyword bashSpecialVariables contained  HISTCMD        INPUTRC
  191.  syn keyword bashStatement             chmod        fgrep       install      rm         sort
  192.  syn keyword bashStatement             clear        find       less          rmdir         strip
  193.  syn keyword bashStatement             du            gnufind       ls          rpm         tail
  194.  syn keyword bashStatement             egrep        gnugrep       mkdir      sed         touch
  195.  syn keyword bashStatement             expr        grep       mv          sleep         complete
  196.  syn keyword bashAdminStatement             daemon        killproc       reload      start         stop
  197.  syn keyword bashAdminStatement             killall        nice       restart      status
  198. endif
  199.  
  200. if exists("b:is_kornshell")
  201.  syn cluster shCommandSubList1 add=kshSpecialVariables,kshStatement
  202.  syn cluster shCaseList           add=kshStatement
  203.  syn keyword kshSpecialVariables contained   CDPATH        HISTFILE       MAILCHECK      PPID         RANDOM
  204.  syn keyword kshSpecialVariables contained   COLUMNS        HISTSIZE       MAILPATH      PS1         REPLY
  205.  syn keyword kshSpecialVariables contained   EDITOR        HOME       OLDPWD      PS2         SECONDS
  206.  syn keyword kshSpecialVariables contained   ENV        IFS           OPTARG      PS3         SHELL
  207.  syn keyword kshSpecialVariables contained   ERRNO        LINENO       OPTIND      PS4         TMOUT
  208.  syn keyword kshSpecialVariables contained   FCEDIT        LINES       PATH          PWD         VISUAL
  209.  syn keyword kshSpecialVariables contained   FPATH        MAIL
  210.  syn keyword kshStatement             cat        expr       less          printenv     strip
  211.  syn keyword kshStatement             chmod        fgrep       ls          rm         stty
  212.  syn keyword kshStatement             clear        find       mkdir      rmdir         tail
  213.  syn keyword kshStatement             cp            grep       mv          sed         touch
  214.  syn keyword kshStatement             du            install       nice          sort         tput
  215.  syn keyword kshStatement             egrep        killall
  216. endif
  217.  
  218. syn match   shSource          "^\.\s"
  219. syn match   shSource          "\s\.\s"
  220. syn region  shColon          start="^\s*:" end="$\|" end="#"me=e-1 contains=@shColonList
  221.  
  222. " String and Character constants
  223. "===============================
  224. syn match   shNumber                 "-\=\<\d\+\>"
  225. syn match   shSpecial          contained         "\\\d\d\d\|\\[abcfnrtv0]"
  226. syn region  shSingleQuote     matchgroup=shOperator start=+'+ end=+'+              contains=shStringSpecial
  227. syn region  shDoubleQuote     matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+      contains=@shDblQuoteList,shStringSpecial
  228. syn match   shStringSpecial   contained         "[^[:print:]]"
  229. syn match   shSpecial                 "\\[\\\"\'`$()#]"
  230.  
  231. " Comments
  232. "=========
  233. syn cluster    shCommentGroup contains=shTodo
  234. syn keyword    shTodo          contained         TODO
  235. syn match      shComment             "#.*$" contains=@shCommentGroup
  236.  
  237. " File redirection highlighted as operators
  238. "==========================================
  239. syn match      shRedir          "\d\=>\(&[-0-9]\)\="
  240. syn match      shRedir          "\d\=>>-\="
  241. syn match      shRedir          "\d\=<\(&[-0-9]\)\="
  242. syn match      shRedir          "\d<<-\="
  243.  
  244. " Shell Input Redirection (Here Documents)
  245. if version < 600
  246.  syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**"  matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
  247.  syn region shHereDoc matchgroup=shRedir start="<<-\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^\s*END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
  248.  syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**"  matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
  249.  syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
  250.  syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**"  matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
  251.  syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
  252. elseif g:sh_fold_enabled
  253.  syn region shHereDoc matchgroup=shRedir fold start="<<\s*\**\z(\S*\)\**"          matchgroup=shRedir end="^\z1$"    contains=@shDblQuoteList
  254.  syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\**\z(\S*\)\**"          matchgroup=shRedir end="^\s*\z1$" contains=@shDblQuoteList
  255.  syn region shHereDoc matchgroup=shRedir fold start="<<\s*\**\z(["'\\]\S*\)\**"          matchgroup=shRedir end="^\z1$"
  256.  syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\**\z(["'\\]\S*\)\**"      matchgroup=shRedir end="^\s*\z1$"
  257. else
  258.  syn region shHereDoc matchgroup=shRedir start="<<\s*\**\z(\S*\)\**"        matchgroup=shRedir end="^\z1$" contains=@shDblQuoteList
  259.  syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\z(\S*\)\**"        matchgroup=shRedir end="^\s*\z1$" contains=@shDblQuoteList
  260.  syn region shHereDoc matchgroup=shRedir start="<<\s*\**\z(["'\\]\S*\)\**"  matchgroup=shRedir end="^\z1$"
  261.  syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\z(["'\\]\S*\)\**" matchgroup=shRedir end="^\s*\z1$"
  262. endif
  263.  
  264. " Identifiers
  265. "============
  266. syn match  shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze="       nextgroup=shSetIdentifier
  267. syn match  shIdWhiteSpace  contained         "\s"
  268. syn match  shSetIdentifier contained         "="        nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shSingleQuote
  269. if exists("b:is_bash")
  270.   syn region shSetList matchgroup=shSet start="\<\(declare\|typeset\|local\|export\|unset\)\>[^/]"me=e-1 end="$" end="[|)]"me=e-1 matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="#\|="me=e-1 contains=@shIdList
  271.   syn region shSetList matchgroup=shSet start="\<set\>[^/]"me=e-1 end="$" end="[|)]"me=e-1         matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
  272.   syn match  shSet "\<\(declare\|typeset\|local\|export\|set\|unset\)$"
  273. elseif exists("b:is_kornshell")
  274.   syn region shSetList matchgroup=shSet start="\<\(typeset\|export\|unset\)\>[^/]"me=e-1 end="$" end="[)|]"me=e-1    matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
  275.   syn region shSetList matchgroup=shSet start="\<set\>[^/]"me=e-1 end="$" end="[)|]"me=e-1                matchgroup=shOperator end="[;&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
  276.   syn match  shSet "\<\(typeset\|set\|export\|unset\)$"
  277. else
  278.   syn region shSetList matchgroup=shSet start="\<\(set\|export\|unset\)\>[^/]"me=e-1 end="$" end="[)|]"me=e-1 matchgroup=shOperator end="[;&]" matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
  279.   syn match  shStatement "\<\(set\|export\|unset\)$"
  280. endif
  281.  
  282. " handles functions which start:  Function () {
  283. "   Apparently Bourne shell accepts functions too,
  284. "   even though it isn't documented by my man pages
  285. "   for it.
  286. syn cluster shCommandSubList1  add=bkshFunction
  287. syn match   bkshFunction             "^\s*\<\h\w*\>\s*()"       skipwhite skipnl nextgroup=bkshFunctionRegion contains=bkshFunctionParen
  288. if g:sh_fold_enabled
  289.  syn region  bkshFunctionRegion transparent contained fold  matchgroup=Delimiter start="{" end="}" contains=@shFunctionList
  290. else
  291.  syn region  bkshFunctionRegion transparent contained        matchgroup=Delimiter start="{" end="}" contains=@shFunctionList
  292. endif
  293. syn match   bkshFunctionParen  contained     "[()]"
  294.  
  295. " Parameter Dereferencing
  296. " =======================
  297. syn match  shDerefSimple             "\$\w\+"                      nextgroup=shDerefVarArray
  298. syn region shDeref                 matchgroup=PreProc start="\${" end="}"      contains=@shDerefList nextgroup=shDerefVarArray
  299. syn match  shDerefWordError   contained         "[^}$[]"
  300. syn match  shDerefSimple             "\$[-_#*@!?]"
  301. if exists("b:is_bash") || exists("b:is_kornshell")
  302.  syn match  shDerefSimple             "\$\$"
  303.  syn region shDeref                 matchgroup=PreProc start="\${##\=" end="}"      contains=@shDerefList
  304. endif
  305.  
  306. "     bash : ${!prefix*}
  307. "     bash : ${#parameter}
  308. if exists("b:is_bash")
  309.  syn region shDeref                 matchgroup=PreProc start="\${!" end="\*\=}"  contains=@shDerefList,shDerefOp
  310.  syn match  shDerefVar          contained         "{\@<=!\w\+"                  nextgroup=@shDerefVarList
  311. endif
  312.  
  313. syn match  shDerefSpecial     contained         "{\@<=[-*@?0]"                  nextgroup=shDerefOp,shDerefOpError
  314. syn match  shDerefSpecial     contained         "\({[#!]\)\@<=[[:alnum:]*@_]\+"          nextgroup=@shDerefVarList,shDerefOp
  315. syn match  shDerefVar          contained         "{\@<=\w\+"                  nextgroup=@shDerefVarList
  316.  
  317. " sh ksh bash : ${var[... ]...}  array reference
  318. syn region  shDerefVarArray   contained         matchgroup=shDeref start="\[" end="]"      contains=@shCommandSubList2 nextgroup=shDerefOp,shDerefOpError
  319.  
  320. " sh ksh bash : ${parameter:-word}    word is default value
  321. " sh ksh bash : ${parameter:=word}    assign word as default value
  322. " sh ksh bash : ${parameter:?word}    display word if parameter is null
  323. " sh ksh bash : ${parameter:+word}    use word if parameter is not null, otherwise nothing
  324. "    ksh bash : ${parameter#pattern}  remove small left  pattern
  325. "    ksh bash : ${parameter##pattern} remove large left  pattern
  326. "    ksh bash : ${parameter%pattern}  remove small right pattern
  327. "    ksh bash : ${parameter%%pattern} remove large right pattern
  328. syn cluster shDerefPatternList             contains=shDerefPattern,shDerefString
  329. syn match shDerefOpError      contained         ":[[:punct:]]"
  330. syn match  shDerefOp          contained         ":\=[-=?]"        nextgroup=@shDerefPatternList
  331. syn match  shDerefOp          contained         ":\=+"        nextgroup=@shDerefPatternList
  332. if exists("b:is_bash") || exists("b:is_kornshell")
  333.  syn match  shDerefOp          contained         "#\{1,2}"        nextgroup=@shDerefPatternList
  334.  syn match  shDerefOp          contained         "%\{1,2}"        nextgroup=@shDerefPatternList
  335.  syn match  shDerefPattern    contained         "[^{}]\+"        contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub nextgroup=shDerefPattern
  336.  syn region shDerefPattern    contained         start="{" end="}"           contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
  337. endif
  338. syn region shDerefString      contained         matchgroup=shOperator start=+'+ end=+'+             contains=shStringSpecial
  339. syn region shDerefString      contained         matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+         contains=@shDblQuoteList,shStringSpecial
  340. syn match  shDerefString      contained         "\\["']"
  341.  
  342. "     bash : ${parameter:offset}
  343. "     bash : ${parameter:offset:length}
  344. "     bash : ${parameter//pattern/string}
  345. "     bash : ${parameter//pattern}
  346. if exists("b:is_bash")
  347.  syn region shDerefOp          contained         start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList2 nextgroup=shDerefPOL
  348.  syn match  shDerefPOL          contained         ":[^}]\{1,}"   contains=@shCommandSubList2
  349.  syn match  shDerefOp          contained         "/\{1,2}"        nextgroup=shDerefPat
  350.  syn match  shDerefPat          contained         "[^/}]\{1,}"   nextgroup=shDerefPatStringOp
  351.  syn match  shDerefPatStringOp contained     "/"        nextgroup=shDerefPatString
  352.  syn match  shDerefPatString  contained         "[^}]\{1,}"
  353. endif
  354.  
  355. " A bunch of useful sh keywords
  356. syn keyword shStatement          break         eval        newgrp       return      ulimit
  357. syn keyword shStatement          cd         exec        pwd           shift      umask
  358. syn keyword shStatement          chdir         exit        read       test          wait
  359. syn keyword shStatement          continue         kill        readonly       trap
  360. syn keyword shConditional     contained         elif        else       then
  361. syn keyword shCondError                 elif        else       then
  362.  
  363. if exists("b:is_kornshell") || exists("b:is_bash")
  364.  syn keyword shFunction          function
  365.  syn keyword shStatement      alias         fg            integer       printf      times
  366.  syn keyword shStatement      autoload         functions        jobs       r          true
  367.  syn keyword shStatement      bg         getopts        let           stop          type
  368.  syn keyword shStatement      false         hash        nohup       suspend      unalias
  369.  syn keyword shStatement      fc         history        print       time          whence
  370.  
  371.  if exists("b:is_bash")
  372.   syn keyword shStatement     bind         disown        local       popd          shopt
  373.   syn keyword shStatement     builtin         enable        logout       pushd      source
  374.   syn keyword shStatement     dirs         help
  375.  else
  376.   syn keyword shStatement     login         newgrp
  377.  endif
  378. endif
  379.  
  380. " Syncs
  381. " =====
  382. if !exists("sh_minlines")
  383.   let sh_minlines = 200
  384. endif
  385. if !exists("sh_maxlines")
  386.   let sh_maxlines = 2 * sh_minlines
  387. endif
  388. exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
  389. syn sync match shCaseEsacSync grouphere         shCaseEsac        "\<case\>"
  390. syn sync match shCaseEsacSync groupthere     shCaseEsac        "\<esac\>"
  391. syn sync match shDoSync          grouphere         shDo        "\<do\>"
  392. syn sync match shDoSync          groupthere     shDo        "\<done\>"
  393. syn sync match shForSync      grouphere         shFor        "\<for\>"
  394. syn sync match shForSync      groupthere     shFor        "\<in\>"
  395. syn sync match shIfSync          grouphere         shIf        "\<if\>"
  396. syn sync match shIfSync          groupthere     shIf        "\<fi\>"
  397. syn sync match shUntilSync    grouphere         shRepeat        "\<until\>"
  398. syn sync match shWhileSync    grouphere         shRepeat        "\<while\>"
  399.  
  400. " The default highlighting.
  401. hi def link shArithRegion             shShellVariables
  402. hi def link shCaseBar                 shConditional
  403. hi def link shCaseIn                 shConditional
  404. hi def link shCaseCommandSub             shCommandSub
  405. hi def link shCaseDoubleQuote             shDoubleQuote
  406. hi def link shCaseSingleQuote             shSingleQuote
  407. hi def link shCaseStart                 shConditional
  408. hi def link shCmdSubRegion             shShellVariables
  409. hi def link shColon                 shStatement
  410.  
  411. hi def link shDeref                 shShellVariables
  412. hi def link shDerefOp                 shOperator
  413.  
  414. hi def link shDerefVar                 shDeref
  415. hi def link shDerefPOL                 shDerefOp
  416. hi def link shDerefPatString             shDerefPattern
  417. hi def link shDerefPatStringOp             shDerefOp
  418. hi def link shDerefSimple             shDeref
  419. hi def link shDerefSpecial             shDeref
  420. hi def link shDerefString             shDoubleQuote
  421.  
  422. hi def link shDoubleQuote             shString
  423. hi def link shEcho                 shString
  424. hi def link shEmbeddedEcho             shString
  425. hi def link shHereDoc                 shString
  426. hi def link shLoop                 shStatement
  427. hi def link shOption                 shCommandSub
  428. hi def link shPattern                 shString
  429. hi def link shPosnParm                 shShellVariables
  430. hi def link shRange                 shOperator
  431. hi def link shRedir                 shOperator
  432. hi def link shSingleQuote             shString
  433. hi def link shSource                 shOperator
  434. hi def link shStringSpecial             shSpecial
  435. hi def link shSubShRegion             shOperator
  436. hi def link shTestOpr                 shConditional
  437. hi def link shVariable                 shSetList
  438. hi def link shWrapLineOperator             shOperator
  439.  
  440. if exists("b:is_bash")
  441.   hi def link bashAdminStatement         shStatement
  442.   hi def link bashSpecialVariables         shShellVariables
  443.   hi def link bashStatement             shStatement
  444.   hi def link bkshFunction             Function
  445.   hi def link bkshFunctionParen             Delimiter
  446. endif
  447. if exists("b:is_kornshell")
  448.   hi def link kshSpecialVariables         shShellVariables
  449.   hi def link kshStatement             shStatement
  450.   hi def link bkshFunction             Function
  451.   hi def link bkshFunctionParen             Delimiter
  452. endif
  453.  
  454. hi def link shCaseError                 Error
  455. hi def link shCondError                 Error
  456. hi def link shCurlyError             Error
  457. hi def link shDerefError             Error
  458. hi def link shDerefOpError             Error
  459. hi def link shDerefWordError             Error
  460. hi def link shDoError                 Error
  461. hi def link shEsacError                 Error
  462. hi def link shIfError                 Error
  463. hi def link shInError                 Error
  464. hi def link shParenError             Error
  465. hi def link shTestError                 Error
  466. if exists("b:is_kornshell")
  467.   hi def link shDTestError             Error
  468. endif
  469.  
  470. hi def link shArithmetic             Special
  471. hi def link shCharClass                 Identifier
  472. hi def link shSnglCase                 Statement
  473. hi def link shCommandSub             Special
  474. hi def link shComment                 Comment
  475. hi def link shConditional             Conditional
  476. hi def link shExprRegion             Delimiter
  477. hi def link shFunction                 Function
  478. hi def link shFunctionName             Function
  479. hi def link shNumber                 Number
  480. hi def link shOperator                 Operator
  481. hi def link shRepeat                 Repeat
  482. hi def link shSet                 Statement
  483. hi def link shSetList                 Identifier
  484. hi def link shShellVariables             PreProc
  485. hi def link shSpecial                 Special
  486. hi def link shStatement                 Statement
  487. hi def link shString                 String
  488. hi def link shTodo                 Todo
  489.  
  490. " Current Syntax
  491. " ==============
  492. if exists("b:is_bash")
  493.  let b:current_syntax = "bash"
  494. elseif exists("b:is_kornshell")
  495.  let b:current_syntax = "ksh"
  496. else
  497.  let b:current_syntax = "sh"
  498. endif
  499.  
  500. " vim: ts=8
  501.