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 / mac / vim55rt.sit / runtime / syntax / sh.vim < prev    next >
Encoding:
Text File  |  1999-09-25  |  15.8 KB  |  329 lines  |  [TEXT/VIM!]

  1. " Vim syntax file
  2. " Language:        shell (sh) Korn shell (ksh) bash (sh)
  3. " Maintainer:        Dr. Charles E. Campbell, Jr. <charles.campbell@gsfc.nasa.gov>
  4. " Previous Maintainer:    Lennart Schultz <Lennart.Schultz@ecmwf.int>
  5. " Last Change:    May 26, 1999
  6. " Version: 1.08
  7. "
  8. " Using the following VIM variables:
  9. " is_kornshell               if defined enhance with kornshell syntax
  10. " is_bash                    if defined enhance with bash syntax
  11. "
  12. " This is a complete redesign including many ideas from
  13. " â•”ric Brunet (eric.brunet@ens.fr)
  14.  
  15. " Remove any old syntax stuff hanging around
  16. syn clear
  17. " sh syntax is case sensitive
  18. syn case match
  19.  
  20. " This one is needed INSIDE a CommandSub, so that
  21. " `echo bla` be correct
  22. 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=shNumber,shCommandSub,shSinglequote,shDeref,shSpecialVar,shSpecial,shOperator,shDoubleQuote
  23.  
  24. " This must be after the strings, so that bla \" be correct
  25. syn region shEmbeddedEcho contained matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=shNumber,shSinglequote,shDeref,shSpecialVar,shSpecial,shOperator,shDoubleQuote
  26.  
  27. "Error Codes
  28. syn match   shDoError "\<done\>"
  29. syn match   shIfError "\<fi\>"
  30. syn match   shInError "\<in\>"
  31. syn match   shCaseError ";;"
  32. syn match   shEsacError "\<esac\>"
  33. syn match   shCurlyError "}"
  34. syn match   shParenError ")"
  35. if exists("is_kornshell")
  36.  syn match     shDTestError "]]"
  37. endif
  38. syn match     shTestError "]"
  39.  
  40. " Options interceptor
  41. syn match   shOption  "[\-+][a-zA-Z0-9]\+\>"
  42.  
  43. " error clusters:
  44. "================
  45. syn cluster shErrorList    contains=shCaseError,shCurlyError,shDTestError,shDerefError,shDoError,shEsacError,shIfError,shInError,shParenError,shTestError
  46. syn cluster shErrorFuncList    contains=shDerefError
  47. syn cluster shErrorLoopList    contains=shCaseError,shDTestError,shDerefError,shDoError,shInError,shParenError,shTestError
  48. syn cluster shErrorCaseList    contains=shCaseError,shDerefError,shDTestError,shDoError,shInError,shParenError,shTestError
  49. syn cluster shErrorColonList    contains=shDerefError
  50. syn cluster shErrorNoneList    contains=shDerefError
  51.  
  52. " clusters: contains=@... clusters
  53. "==================================
  54. syn cluster shCaseEsacList    contains=shCase,shCaseBar,shCaseIn,shComment,shDeref,shCommandSub
  55. syn cluster shIdList    contains=shCommandSub,shCurlyError,shDeref,shTestError,shWrapLineOperator,shIdWhiteSpace
  56. syn cluster shDblQuoteList    contains=shCommandSub,shDeref,shSpecial,shSpecialShellVar
  57.  
  58. " clusters: contains=ALLBUT,@... clusters
  59. "=========================================
  60. syn cluster shCaseList    contains=shFunction,shCase,shCaseBar,shDerefOp,shDerefText,@shErrorCaseList,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shIdWhiteSpace,shDerefTextError,shPattern
  61. syn cluster shColonList    contains=shCase,shCaseBar,shDerefOp,shDerefText,shFunction,shTestOpr,@shErrorColonList,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shIdWhiteSpace,shDerefTextError,shPattern
  62. syn cluster shCommandSubList1    contains=shCase,shCaseBar,shCommandSub,shDerefOp,shDerefText,shEcho,shFunction,shTestOpr,@shErrorList,shDerefVar,shDerefOpError,shStringSpecial,shIdWhiteSpace,shDerefTextError,shPattern
  63. syn cluster shCommandSubList2    contains=shCase,shCaseBar,shDerefOp,shDerefText,shEcho,shFunction,shTestOpr,@shErrorList,shDerefVar,shDerefOpError,shStringSpecial,shIdWhiteSpace,shDerefTextError,shPattern
  64. syn cluster shLoopList    contains=shFunction,@shErrorLoopList,shCase,shInEsac,shCaseBar,shDerefOp,shDerefText,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shIdWhiteSpace,shDerefTextError,shPattern
  65. syn cluster shExprList1    contains=shCase,shCaseBar,shDerefOp,shDerefText,shFunction,shIdentifier,@shErrorNoneList,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shIdWhiteSpace,shDerefTextError,shPattern
  66. syn cluster shExprList2    contains=shCase,shCaseBar,shDerefOp,shDerefText,@shErrorNoneList,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shIdWhiteSpace,shDerefTextError,shPattern
  67. syn cluster shSubShList    contains=shCase,shCaseBar,shDerefOp,shDerefText,shParenError,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shDerefError,shIdWhiteSpace,shDerefTextError,shPattern
  68. syn cluster shTestList    contains=shCase,shCaseBar,shDTestError,shDerefError,shDerefOp,shDerefText,shFunction,shIdentifier,shTestError,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shIdWhiteSpace,shDerefTextError,shPattern
  69. syn cluster shFunctionList    contains=shCase,shCaseBar,@shErrorFuncList,shDerefOp,shDerefText,shFunction,shDerefVar,shDerefOpError,shStringSpecial,shSkipInitWS,shIdWhiteSpace,shDerefTextError,shPattern
  70.  
  71. " Tests
  72. "======
  73. syn region  shExpr transparent matchgroup=shOperator start="\[" skip=+\\\\\|\\$+ end="\]" contains=ALLBUT,@shTestList
  74. syn region  shExpr transparent matchgroup=shStatement start="\<test\>" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=ALLBUT,@shExprList1
  75. if exists("is_kornshell")
  76.  syn region  shExpr transparent matchgroup=shOperator start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=ALLBUT,@shTestList
  77. endif
  78. syn match   shTestOpr contained "[!=]\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>"
  79.  
  80. " do, if
  81. syn region shDo  transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=ALLBUT,@shLoopList
  82. syn region shIf  transparent matchgroup=shConditional start="\<if\>" matchgroup=shConditional end="\<fi\>"   contains=ALLBUT,@shLoopList
  83. syn region shFor matchgroup=shStatement start="\<for\>" end="\<in\>" end="\<do\>"me=e-2    contains=ALLBUT,@shLoopList
  84.  
  85. " case
  86. syn region  shCaseEsac matchgroup=shConditional start="\<case\>" matchgroup=shConditional end="\<esac\>" contains=@shCaseEsacList
  87. syn keyword shCaseIn  contained skipwhite skipnl in            nextgroup=shCase,shCaseBar,shComment
  88. syn region  shCase    contained skipwhite skipnl matchgroup=shConditional start="[^$)]\{-})"ms=s,hs=e  end=";;" end="esac"me=s-1 contains=ALLBUT,@shCaseList nextgroup=shCase,shCaseBar,shComment
  89. syn match   shCaseBar contained "[^|)]\{-}|"hs=e            nextgroup=shCase,shCaseBar
  90.  
  91. syn region shExpr  transparent matchgroup=shOperator start="{" end="}"        contains=ALLBUT,@shExprList2
  92. syn region shSubSh transparent matchgroup=shOperator start="(" end=")"        contains=ALLBUT,@shSubShList
  93.  
  94. " Misc
  95. "=====
  96. syn match   shOperator    "[!&;|]"
  97. syn match   shOperator    "!\=="    skipwhite nextgroup=shPattern
  98. syn match   shPattern    "\<\S*\>"    contained
  99. syn match   shWrapLineOperator "\\$"
  100. syn region  shCommandSub   start="`" skip="\\`" end="`" contains=ALLBUT,@shCommandSubList1
  101. if exists("is_kornshell") || exists("is_bash")
  102.  syn region shCommandSub matchgroup=shDeref start="$(" end=")" contains=ALLBUT,@shCommandSubList2
  103.  syn match shSkipInitWS contained    "^\s\+"
  104. endif
  105.  
  106. if exists("is_bash")
  107.  syn keyword bashSpecialVariables contained    BASH    HISTCONTROL    LANG    OPTERR    PWD
  108.  syn keyword bashSpecialVariables contained    BASH_ENV    HISTFILE    LC_ALL    OPTIND    RANDOM
  109.  syn keyword bashSpecialVariables contained    BASH_VERSINFO    HISTFILESIZE    LC_COLLATE    OSTYPE    REPLY
  110.  syn keyword bashSpecialVariables contained    BASH_VERSION    HISTIGNORE    LC_MESSAGES    PATH    SECONDS
  111.  syn keyword bashSpecialVariables contained    CDPATH    HISTSIZE    LINENO    PIPESTATUS    SHELLOPTS
  112.  syn keyword bashSpecialVariables contained    DIRSTACK    HOME    MACHTYPE    PPID    SHLVL
  113.  syn keyword bashSpecialVariables contained    EUID    HOSTFILE    MAIL    PROMPT_COMMAND    TIMEFORMAT
  114.  syn keyword bashSpecialVariables contained    FCEDIT    HOSTNAME    MAILCHECK    PS1    TIMEOUT
  115.  syn keyword bashSpecialVariables contained    FIGNORE    HOSTTYPE    MAILPATH    PS2    UID
  116.  syn keyword bashSpecialVariables contained    GLOBIGNORE    IFS    OLDPWD    PS3    auto_resume
  117.  syn keyword bashSpecialVariables contained    GROUPS    IGNOREEOF    OPTARG    PS4    histchars
  118.  syn keyword bashSpecialVariables contained    HISTCMD    INPUTRC
  119.  syn keyword bashStatement        chmod    fgrep    install    rm    sort
  120.  syn keyword bashStatement        clear    find    less    rmdir    strip
  121.  syn keyword bashStatement        du    gnufind    ls    rpm    tail
  122.  syn keyword bashStatement        egrep    gnugrep    mkdir    sed    touch
  123.  syn keyword bashStatement        expr    grep    mv    sleep
  124.  syn keyword bashAdminStatement    daemon    killproc    reload    start    stop
  125.  syn keyword bashAdminStatement    killall    nice    restart    status
  126. endif
  127.  
  128. if exists("is_kornshell")
  129.  syn keyword kshSpecialVariables contained    CDPATH    HISTFILE    MAILCHECK    PPID    RANDOM
  130.  syn keyword kshSpecialVariables contained    COLUMNS    HISTSIZE    MAILPATH    PS1    REPLY
  131.  syn keyword kshSpecialVariables contained    EDITOR    HOME    OLDPWD    PS2    SECONDS
  132.  syn keyword kshSpecialVariables contained    ENV    IFS    OPTARG    PS3    SHELL
  133.  syn keyword kshSpecialVariables contained    ERRNO    LINENO    OPTIND    PS4    TMOUT
  134.  syn keyword kshSpecialVariables contained    FCEDIT    LINES    PATH    PWD    VISUAL
  135.  syn keyword kshSpecialVariables contained    FPATH    MAIL
  136.  syn keyword kshStatement        cat    expr    less    printenv    strip
  137.  syn keyword kshStatement        chmod    fgrep    ls    rm    stty
  138.  syn keyword kshStatement        clear    find    mkdir    rmdir    tail
  139.  syn keyword kshStatement        cp    grep    mv    sed    touch
  140.  syn keyword kshStatement        du    install    nice    sort    tput
  141.  syn keyword kshStatement        egrep    killall
  142. endif
  143.  
  144. syn match   shSource    "^\.\s"
  145. syn match   shSource    "\s\.\s"
  146. syn region  shColon    start="^\s*:" end="$\|" end="#"me=e-1 contains=ALLBUT,@shColonList
  147.  
  148. " Comments
  149. "=========
  150. syn keyword    shTodo    contained    TODO
  151. syn match    shComment        "#.*$" contains=shTodo
  152.  
  153. " String and Character constants
  154. "===============================
  155. syn match   shNumber        "-\=\<\d\+\>"
  156. syn match   shSpecial    contained    "\\\d\d\d\|\\[abcfnrtv]"
  157. syn region  shSinglequote    matchgroup=shOperator start=+'+ end=+'+        contains=shStringSpecial
  158. syn region  shDoubleQuote     matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+    contains=@shDblQuoteList,shStringSpecial
  159. syn match   shStringSpecial    contained    "[^[:print:]]"
  160. syn match   shSpecial        "\\[\\\"\'`$]"
  161.  
  162. " File redirection highlighted as operators
  163. "==========================================
  164. syn match    shRedir    "\d\=>\(&[-0-9]\)\="
  165. syn match    shRedir    "\d\=>>-\="
  166. syn match    shRedir    "\d\=<\(&[-0-9]\)\="
  167. syn match    shRedir    "\d<<-\="
  168.  
  169. " Shell Input Redirection (Here Documents)
  170. syn region shHereDoc matchgroup=shRedir start="<<-\=\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$"
  171. syn region shHereDoc matchgroup=shRedir start="<<-\=\s*\**EOF\**" matchgroup=shRedir end="^EOF$"
  172.  
  173. " Identifiers
  174. "============
  175. syn match  shIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>="me=e-1
  176. syn match  shIdWhiteSpace contained    "\s"
  177. if exists("is_bash")
  178.  syn region shIdentifier matchgroup=shStatement start="\<\(declare\|typeset\|local\|export\|set\|unset\)\>[^/]"me=e-1 matchgroup=shOperator end="$\|[;&|]" matchgroup=NONE end="#\|="me=e-1 contains=@shIdList
  179. elseif exists("is_kornshell")
  180.  syn region shIdentifier matchgroup=shStatement start="\<\(typeset\|set\|export\|unset\)\>[^/]"me=e-1 matchgroup=shOperator end="$\|[;&|]" matchgroup=NONE end="#\|="me=e-1 contains=@shIdList
  181. else
  182.  syn region shIdentifier matchgroup=shStatement start="\<\(set\|export\|unset\)\>[^/]"me=e-1 matchgroup=shOperator end="$\|[;&|]" matchgroup=NONE end="#\|="me=e-1 contains=@shIdList
  183. endif
  184.  
  185. " The [^/] in the start pattern is a kludge to avoid bad
  186. " highlighting with cd /usr/local/lib...
  187. syn region shFunction    transparent    matchgroup=shFunctionName start="^\s*\<[a-zA-Z_][a-zA-Z0-9_]*\>\s*()\s*{" end="}" contains=ALLBUT,@shFunctionList
  188. syn region shDeref    oneline    start="\${" end="}"    contains=shDeref,shDerefVar
  189. syn match  shDeref        "\$[a-zA-Z_][a-zA-Z0-9_]*\>"
  190. syn match  shSpecialShellVar        "\$[-#@*$?!0-9]"
  191. syn match  shDerefVar    contained    "[0-9]\+\>"        nextgroup=shDerefOp,shDerefError,shDerefOpError,shExpr
  192. syn match  shDerefVar    contained    "[a-zA-Z_][a-zA-Z0-9_]*\>"    nextgroup=shDerefOp,shDerefError,shDerefOpError,shExpr
  193. syn match  shDerefVar    contained    "[-#@*?!]"        nextgroup=shDerefOp,shDerefError,shDerefOpError,shExpr
  194. syn match  shDerefVar    contained    "\$[^{(]"me=s+1    nextgroup=shDerefOp,shDerefError,shDerefOpError,shExpr
  195. syn match  shDerefOpError    contained    "[^:}[]"
  196. syn match  shDerefOp    contained    ":\=[-=?+]"        nextgroup=shDerefText
  197. syn region shDerefText    contained    start="[^{}]" end="}"me=e-1    contains=shDeref,shCommandSub,shDoubleQuote,shSingleQuote,shDerefTextError
  198. syn match  shDerefTextError    contained    "^."
  199. syn match  shDerefError    contained    "\s.\{-}}"me=e-1
  200. syn region shDerefText    contained    start="{"    end="}"    contains=shDeref,shCommandSub
  201.  
  202. if exists("is_kornshell")
  203.  syn match shDeref        "\${#[*@]\=}"
  204.  syn match shDeref        "\${#[a-zA-Z_]\+}"
  205.  syn match shDerefOp    contained    "##\|%%\|[#%]"    nextgroup=shDerefText
  206. endif
  207.  
  208. " A bunch of useful sh keywords
  209. syn keyword shStatement    break    eval    newgrp    return    ulimit
  210. syn keyword shStatement    cd    exec    pwd    shift    umask
  211. syn keyword shStatement    chdir    exit    read    test    wait
  212. syn keyword shStatement    continue    kill    readonly    trap
  213. syn keyword shConditional    elif    else    then    while
  214.  
  215. if exists("is_kornshell") || exists("is_bash")
  216.  syn keyword shFunction    function
  217.  syn keyword shRepeat    select    until
  218.  syn keyword shStatement    alias    fg    integer    printf    times
  219.  syn keyword shStatement    autoload    functions    jobs    r    true
  220.  syn keyword shStatement    bg    getopts    let    stop    type
  221.  syn keyword shStatement    false    hash    nohup    suspend    unalias
  222.  syn keyword shStatement    fc    history    print    time    whence
  223.  
  224.  if exists("is_bash")
  225.   syn keyword shStatement    bind    disown    help    popd    shopt
  226.   syn keyword shStatement    builtin    enable    logout    pushd    source
  227.   syn keyword shStatement    dirs
  228.  else
  229.   syn keyword shStatement    login    newgrp
  230.  endif
  231. endif
  232.  
  233. " Syncs
  234. " =====
  235. if !exists("sh_minlines")
  236.   let sh_minlines = 200
  237. endif
  238. if !exists("sh_maxlines")
  239.   let sh_maxlines = 2 * sh_minlines
  240. endif
  241. exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
  242. syn sync match shDoSync       grouphere  shDo       "\<do\>"
  243. syn sync match shDoSync       groupthere shDo       "\<done\>"
  244. syn sync match shIfSync       grouphere  shIf       "\<if\>"
  245. syn sync match shIfSync       groupthere shIf       "\<fi\>"
  246. syn sync match shForSync      grouphere  shFor      "\<for\>"
  247. syn sync match shForSync      groupthere shFor      "\<in\>"
  248. syn sync match shCaseEsacSync grouphere  shCaseEsac "\<case\>"
  249. syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
  250.  
  251. " Highlighting
  252. " ============
  253. if !exists("did_sh_syntax_inits")
  254.  " The default methods for highlighting. Can be overridden later
  255.  let did_sh_syntax_inits = 1
  256.  
  257.  hi link shCaseBar        shConditional
  258.  hi link shCaseIn        shConditional
  259.  hi link shColon        shStatement
  260.  hi link shDeref        shShellVariables
  261.  hi link shDerefOp        shOperator
  262.  hi link shDerefVar        shShellVariables
  263.  hi link shDoubleQuote        shString
  264.  hi link shEcho        shString
  265.  hi link shEmbeddedEcho        shString
  266.  hi link shHereDoc        shString
  267.  hi link shOption        shCommandSub
  268.  hi link shPattern        shString
  269.  hi link shRedir        shOperator
  270.  hi link shSinglequote        shString
  271.  hi link shSource        shOperator
  272.  hi link shSpecialShellVar        shShellVariables
  273.  hi link shStringSpecial        shSpecial
  274.  hi link shTestOpr        shConditional
  275.  hi link shWrapLineOperator        shOperator
  276.  
  277.  if exists("is_bash")
  278.   hi link bashAdminStatement        shStatement
  279.   hi link bashSpecialVariables    shShellVariables
  280.   hi link bashStatement        shStatement
  281.  endif
  282.  if exists("is_kornshell")
  283.   hi link kshSpecialVariables        shShellVariables
  284.   hi link kshStatement        shStatement
  285.  endif
  286.  
  287.  hi link shCaseError        Error
  288.  hi link shCurlyError        Error
  289.  hi link shDerefError        Error
  290.  hi link shDerefOpError        Error
  291.  hi link shDerefTextError        Error
  292.  hi link shDoError        Error
  293.  hi link shEsacError        Error
  294.  hi link shIfError        Error
  295.  hi link shInError        Error
  296.  hi link shParenError        Error
  297.  hi link shTestError        Error
  298.  if exists("is_kornshell")
  299.   hi link shDTestError        Error
  300.  endif
  301.  
  302.  hi link shCommandSub        Special
  303.  hi link shComment        Comment
  304.  hi link shConditional        Conditional
  305.  hi link shFunction        Function
  306.  hi link shFunctionName        Function
  307.  hi link shIdentifier        Identifier
  308.  hi link shNumber        Number
  309.  hi link shOperator        Operator
  310.  hi link shRepeat        Repeat
  311.  hi link shShellVariables        PreProc
  312.  hi link shSpecial        Special
  313.  hi link shStatement        Statement
  314.  hi link shString        String
  315.  hi link shTodo        Todo
  316. endif
  317.  
  318. " Current Syntax
  319. " ==============
  320. if exists("is_bash")
  321.  let b:current_syntax = "bash"
  322. elseif exists("is_kornshell")
  323.  let b:current_syntax = "ksh"
  324. else
  325.  let b:current_syntax = "sh"
  326. endif
  327.  
  328. " vim: ts=15
  329.