OLD | NEW |
1 Prism.languages.bash = Prism.languages.extend('clike', { | 1 (function(Prism) { |
2 » 'comment': { | 2 » var insideString = { |
3 » » pattern: /(^|[^"{\\])#.*/, | 3 » » variable: [ |
4 » » lookbehind: true | 4 » » » // Arithmetic Environment |
5 » }, | 5 » » » { |
6 » 'string': { | 6 » » » » pattern: /\$?\(\([\w\W]+?\)\)/, |
7 » » //allow multiline string | 7 » » » » inside: { |
8 » » pattern: /("|')(\\?[\s\S])*?\1/, | 8 » » » » » // If there is a $ sign at the beginning
highlight $(( and )) as variable |
9 » » inside: { | 9 » » » » » variable: [{ |
10 » » » //'property' class reused for bash variables | 10 » » » » » » » pattern: /(^\$\(\([\w\W]
+)\)\)/, |
11 » » » 'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^\}]+\})/ | 11 » » » » » » » lookbehind: true |
12 » » } | 12 » » » » » » }, |
13 » }, | 13 » » » » » » /^\$\(\(/, |
14 » // Redefined to prevent highlighting of numbers in filenames | 14 » » » » » ], |
15 » 'number': { | 15 » » » » » number: /\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+(
?:[Ee]-?\d+)?)\b/, |
16 » » pattern: /([^\w\.])-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/, | 16 » » » » » // Operators according to https://www.gn
u.org/software/bash/manual/bashref.html#Shell-Arithmetic |
17 » » lookbehind: true | 17 » » » » » operator: /--?|-=|\+\+?|\+=|!=?|~|\*\*?|
\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/, |
18 » }, | 18 » » » » » // If there is no $ sign at the beginnin
g highlight (( and )) as punctuation |
19 » // Originally based on http://ss64.com/bash/ | 19 » » » » » punctuation: /\(\(?|\)\)?|,|;/ |
20 » 'function': /\b(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bas
h|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|df|diff|d
iff3|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|forma
t|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gz
ip|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|l
print|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|pw
d|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|re
nice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|seq|service|sftp|shift|shop
t|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|s
ync|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|u
seradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wg
et|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)\b/, | 20 » » » » } |
21 » 'keyword': /\b(if|then|else|elif|fi|for|break|continue|while|in|case|fun
ction|select|do|done|until|echo|exit|return|set|declare)\b/ | 21 » » » }, |
22 }); | 22 » » » // Command Substitution |
| 23 » » » { |
| 24 » » » » pattern: /\$\([^)]+\)|`[^`]+`/, |
| 25 » » » » inside: { |
| 26 » » » » » variable: /^\$\(|^`|\)$|`$/ |
| 27 » » » » } |
| 28 » » » }, |
| 29 » » » /\$(?:[a-z0-9_#\?\*!@]+|\{[^}]+\})/i |
| 30 » » ], |
| 31 » }; |
23 | 32 |
24 Prism.languages.insertBefore('bash', 'keyword', { | 33 » Prism.languages.bash = { |
25 » //'property' class reused for bash variables | 34 » » 'shebang': { |
26 » 'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^}]+\})/ | 35 » » » pattern: /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/, |
27 }); | 36 » » » alias: 'important' |
28 Prism.languages.insertBefore('bash', 'comment', { | 37 » » }, |
29 » //shebang must be before comment, 'important' class from css reused | 38 » » 'comment': { |
30 » 'important': /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/ | 39 » » » pattern: /(^|[^"{\\])#.*/, |
31 }); | 40 » » » lookbehind: true |
| 41 » » }, |
| 42 » » 'string': [ |
| 43 » » » //Support for Here-Documents https://en.wikipedia.org/wi
ki/Here_document |
| 44 » » » { |
| 45 » » » » pattern: /((?:^|[^<])<<\s*)(?:"|')?(\w+?)(?:"|')
?\s*\r?\n(?:[\s\S])*?\r?\n\2/g, |
| 46 » » » » lookbehind: true, |
| 47 » » » » inside: insideString |
| 48 » » » }, |
| 49 » » » { |
| 50 » » » » pattern: /("|')(?:\\?[\s\S])*?\1/g, |
| 51 » » » » inside: insideString |
| 52 » » » } |
| 53 » » ], |
| 54 » » 'variable': insideString.variable, |
| 55 » » // Originally based on http://ss64.com/bash/ |
| 56 » » 'function': { |
| 57 » » » pattern: /(^|\s|;|\||&)(?:alias|apropos|apt-get|aptitude
|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chow
n|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|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|gro
updel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifco
nfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logna
me|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|noti
fy-send|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printe
nv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|r
eadonly|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|stra
ce|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|trace
route|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|uni
ts|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|;|\||&)/, |
| 58 » » » lookbehind: true |
| 59 » » }, |
| 60 » » 'keyword': { |
| 61 » » » 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|;|\||&)/, |
| 62 » » » lookbehind: true |
| 63 » » }, |
| 64 » » 'boolean': { |
| 65 » » » pattern: /(^|\s|;|\||&)(?:true|false)(?=$|\s|;|\||&)/, |
| 66 » » » lookbehind: true |
| 67 » » }, |
| 68 » » 'operator': /&&?|\|\|?|==?|!=?|<<<?|>>|<=?|>=?|=~/, |
| 69 » » 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];]/ |
| 70 » }; |
| 71 |
| 72 » var inside = insideString.variable[1].inside; |
| 73 » inside['function'] = Prism.languages.bash['function']; |
| 74 » inside.keyword = Prism.languages.bash.keyword; |
| 75 » inside.boolean = Prism.languages.bash.boolean; |
| 76 » inside.operator = Prism.languages.bash.operator; |
| 77 » inside.punctuation = Prism.languages.bash.punctuation; |
| 78 })(Prism); |
OLD | NEW |