bash.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Language: Bash
  3. Author: vah <[email protected]>
  4. Contributrors: Benjamin Pannell <[email protected]>
  5. Category: common
  6. */
  7. function(hljs) {
  8. var VAR = {
  9. className: 'variable',
  10. variants: [
  11. {begin: /\$[\w\d#@][\w\d_]*/},
  12. {begin: /\$\{(.*?)}/}
  13. ]
  14. };
  15. var QUOTE_STRING = {
  16. className: 'string',
  17. begin: /"/, end: /"/,
  18. contains: [
  19. hljs.BACKSLASH_ESCAPE,
  20. VAR,
  21. {
  22. className: 'variable',
  23. begin: /\$\(/, end: /\)/,
  24. contains: [hljs.BACKSLASH_ESCAPE]
  25. }
  26. ]
  27. };
  28. var APOS_STRING = {
  29. className: 'string',
  30. begin: /'/, end: /'/
  31. };
  32. return {
  33. aliases: ['sh', 'zsh'],
  34. lexemes: /-?[a-z\._]+/,
  35. keywords: {
  36. keyword:
  37. 'if then else elif fi for while in do done case esac function',
  38. literal:
  39. 'true false',
  40. built_in:
  41. // Shell built-ins
  42. // http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
  43. 'break cd continue eval exec exit export getopts hash pwd readonly return shift test times ' +
  44. 'trap umask unset ' +
  45. // Bash built-ins
  46. 'alias bind builtin caller command declare echo enable help let local logout mapfile printf ' +
  47. 'read readarray source type typeset ulimit unalias ' +
  48. // Shell modifiers
  49. 'set shopt ' +
  50. // Zsh built-ins
  51. 'autoload bg bindkey bye cap chdir clone comparguments compcall compctl compdescribe compfiles ' +
  52. 'compgroups compquote comptags comptry compvalues dirs disable disown echotc echoti emulate ' +
  53. 'fc fg float functions getcap getln history integer jobs kill limit log noglob popd print ' +
  54. 'pushd pushln rehash sched setcap setopt stat suspend ttyctl unfunction unhash unlimit ' +
  55. 'unsetopt vared wait whence where which zcompile zformat zftp zle zmodload zparseopts zprof ' +
  56. 'zpty zregexparse zsocket zstyle ztcp',
  57. _:
  58. '-ne -eq -lt -gt -f -d -e -s -l -a' // relevance booster
  59. },
  60. contains: [
  61. {
  62. className: 'meta',
  63. begin: /^#![^\n]+sh\s*$/,
  64. relevance: 10
  65. },
  66. {
  67. className: 'function',
  68. begin: /\w[\w\d_]*\s*\(\s*\)\s*\{/,
  69. returnBegin: true,
  70. contains: [hljs.inherit(hljs.TITLE_MODE, {begin: /\w[\w\d_]*/})],
  71. relevance: 0
  72. },
  73. hljs.HASH_COMMENT_MODE,
  74. QUOTE_STRING,
  75. APOS_STRING,
  76. VAR
  77. ]
  78. };
  79. }