UNPKG

3.88 kBJavaScriptView Raw
1(function(Prism) {
2 var insideString = {
3 variable: [
4 // Arithmetic Environment
5 {
6 pattern: /\$?\(\([\s\S]+?\)\)/,
7 inside: {
8 // If there is a $ sign at the beginning highlight $(( and )) as variable
9 variable: [{
10 pattern: /(^\$\(\([\s\S]+)\)\)/,
11 lookbehind: true
12 },
13 /^\$\(\(/
14 ],
15 number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee]-?\d+)?/,
16 // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
17 operator: /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
18 // If there is no $ sign at the beginning highlight (( and )) as punctuation
19 punctuation: /\(\(?|\)\)?|,|;/
20 }
21 },
22 // Command Substitution
23 {
24 pattern: /\$\([^)]+\)|`[^`]+`/,
25 greedy: true,
26 inside: {
27 variable: /^\$\(|^`|\)$|`$/
28 }
29 },
30 /\$(?:[\w#?*!@]+|\{[^}]+\})/i
31 ]
32 };
33
34 Prism.languages.bash = {
35 'shebang': {
36 pattern: /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/,
37 alias: 'important'
38 },
39 'comment': {
40 pattern: /(^|[^"{\\])#.*/,
41 lookbehind: true
42 },
43 'string': [
44 //Support for Here-Documents https://en.wikipedia.org/wiki/Here_document
45 {
46 pattern: /((?:^|[^<])<<\s*)["']?(\w+?)["']?\s*\r?\n(?:[\s\S])*?\r?\n\2/,
47 lookbehind: true,
48 greedy: true,
49 inside: insideString
50 },
51 {
52 pattern: /(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\1)[^\\])*\1/,
53 greedy: true,
54 inside: insideString
55 }
56 ],
57 'variable': insideString.variable,
58 // Originally based on http://ss64.com/bash/
59 'function': {
60 pattern: /(^|[\s;|&])(?: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|curl|cut|date|dc|dd|ddrescue|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|enable|env|ethtool|eval|exec|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|npm|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|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|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)(?=$|[\s;|&])/,
61 lookbehind: true
62 },
63 'keyword': {
64 pattern: /(^|[\s;|&])(?:let|:|\.|if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)(?=$|[\s;|&])/,
65 lookbehind: true
66 },
67 'boolean': {
68 pattern: /(^|[\s;|&])(?:true|false)(?=$|[\s;|&])/,
69 lookbehind: true
70 },
71 'operator': /&&?|\|\|?|==?|!=?|<<<?|>>|<=?|>=?|=~/,
72 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];]/
73 };
74
75 var inside = insideString.variable[1].inside;
76 inside.string = Prism.languages.bash.string;
77 inside['function'] = Prism.languages.bash['function'];
78 inside.keyword = Prism.languages.bash.keyword;
79 inside['boolean'] = Prism.languages.bash['boolean'];
80 inside.operator = Prism.languages.bash.operator;
81 inside.punctuation = Prism.languages.bash.punctuation;
82
83 Prism.languages.shell = Prism.languages.bash;
84})(Prism);