shell.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Shell patterns
  3. *
  4. * @author Matthew King
  5. * @author Craig Campbell
  6. */
  7. Rainbow.extend('shell', [
  8. /**
  9. * This handles the case where subshells contain quotes.
  10. * For example: `"$(resolve_link "$name" || true)"`.
  11. *
  12. * Caveat: This really should match balanced parentheses, but cannot.
  13. * @see http://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns
  14. */
  15. {
  16. name: 'shell',
  17. matches: {
  18. 1: {
  19. language: 'shell'
  20. }
  21. },
  22. pattern: /\$\(([\s\S]*?)\)/gm
  23. },
  24. {
  25. matches: {
  26. 2: 'string'
  27. },
  28. pattern: /(\(|\s|\[|\=)(('|")[\s\S]*?(\3))/gm
  29. },
  30. {
  31. name: 'keyword.operator',
  32. pattern: /<|>|&/g
  33. },
  34. {
  35. name: 'comment',
  36. pattern: /\#[\s\S]*?$/gm
  37. },
  38. {
  39. name: 'storage.function',
  40. pattern: /(.+?)(?=\(\)\s{0,}\{)/g
  41. },
  42. /**
  43. * Environment variables
  44. */
  45. {
  46. name: 'support.command',
  47. pattern: /\b(echo|rm|ls|(mk|rm)dir|cd|find|cp|exit|pwd|exec|trap|source|shift|unset)/g
  48. },
  49. {
  50. matches: {
  51. 1: 'keyword'
  52. },
  53. pattern: /\b(break|case|continue|do|done|elif|else|esac|eval|export|fi|for|function|if|in|local|return|set|then|unset|until|while)(?=\b)/g
  54. }
  55. ]);