bash.js 2.3 KB

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