home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / OpenLinux 2.3 CD.iso / live / usr / share / vim / syntax / sh.vim < prev    next >
Encoding:
Text File  |  1999-08-10  |  12.7 KB  |  291 lines

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