bash.js 2.4 KB

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