prism-bash.js 2.4 KB

12345678910111213141516171819202122232425262728293031
  1. Prism.languages.bash = Prism.languages.extend('clike', {
  2. 'comment': {
  3. pattern: /(^|[^"{\\])(#.*?(\r?\n|$))/,
  4. lookbehind: true
  5. },
  6. 'string': {
  7. //allow multiline string
  8. pattern: /("|')(\\?[\s\S])*?\1/,
  9. inside: {
  10. //'property' class reused for bash variables
  11. 'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^\}]+\})/
  12. }
  13. },
  14. // Redefined to prevent highlighting of numbers in filenames
  15. 'number': {
  16. pattern: /([^\w\.])-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
  17. lookbehind: true
  18. },
  19. // Originally based on http://ss64.com/bash/
  20. 'function': /\b(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chown|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|cut|date|dc|dd|ddrescue|declare|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|echo|egrep|eject|enable|env|ethtool|eval|exec|exit|expand|expect|export|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logname|logout|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|make|man|mkdir|mkfifo|mkisofs|mknod|more|most|mount|mtools|mtr|mv|mmv|nano|netstat|nice|nl|nohup|notify-send|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printenv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|renice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|select|seq|service|sftp|shift|shopt|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|traceroute|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|units|unrar|unshar|until|uptime|useradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)\b/,
  21. 'keyword': /\b(if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)\b/
  22. });
  23. Prism.languages.insertBefore('bash', 'keyword', {
  24. //'property' class reused for bash variables
  25. 'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^}]+\})/
  26. });
  27. Prism.languages.insertBefore('bash', 'comment', {
  28. //shebang must be before comment, 'important' class from css reused
  29. 'important': /(^#!\s*\/bin\/bash)|(^#!\s*\/bin\/sh)/
  30. });