1 | 'use strict'
|
---|
2 | var refractorBash = require('./bash.js')
|
---|
3 | module.exports = shellSession
|
---|
4 | shellSession.displayName = 'shellSession'
|
---|
5 | shellSession.aliases = []
|
---|
6 | function shellSession(Prism) {
|
---|
7 | Prism.register(refractorBash)
|
---|
8 | ;(function (Prism) {
|
---|
9 | // CAREFUL!
|
---|
10 | // The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
|
---|
11 | var strings = [
|
---|
12 | // normal string
|
---|
13 | /"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/.source,
|
---|
14 | /'[^']*'/.source,
|
---|
15 | /\$'(?:[^'\\]|\\[\s\S])*'/.source, // here doc
|
---|
16 | // 2 capturing groups
|
---|
17 | /<<-?\s*(["']?)(\w+)\1\s[\s\S]*?[\r\n]\2/.source
|
---|
18 | ].join('|')
|
---|
19 | Prism.languages['shell-session'] = {
|
---|
20 | command: {
|
---|
21 | pattern: RegExp(
|
---|
22 | // user info
|
---|
23 | /^/.source +
|
---|
24 | '(?:' + // <user> ":" ( <path> )?
|
---|
25 | (/[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+(?::[^\0-\x1F$#%*?"<>:;|]+)?/
|
---|
26 | .source +
|
---|
27 | '|' + // <path>
|
---|
28 | // Since the path pattern is quite general, we will require it to start with a special character to
|
---|
29 | // prevent false positives.
|
---|
30 | /[/~.][^\0-\x1F$#%*?"<>@:;|]*/.source) +
|
---|
31 | ')?' + // shell symbol
|
---|
32 | /[$#%](?=\s)/.source + // bash command
|
---|
33 | /(?:[^\\\r\n \t'"<$]|[ \t](?:(?!#)|#.*$)|\\(?:[^\r]|\r\n?)|\$(?!')|<(?!<)|<<str>>)+/.source.replace(
|
---|
34 | /<<str>>/g,
|
---|
35 | function () {
|
---|
36 | return strings
|
---|
37 | }
|
---|
38 | ),
|
---|
39 | 'm'
|
---|
40 | ),
|
---|
41 | greedy: true,
|
---|
42 | inside: {
|
---|
43 | info: {
|
---|
44 | // foo@bar:~/files$ exit
|
---|
45 | // foo@bar$ exit
|
---|
46 | // ~/files$ exit
|
---|
47 | pattern: /^[^#$%]+/,
|
---|
48 | alias: 'punctuation',
|
---|
49 | inside: {
|
---|
50 | user: /^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,
|
---|
51 | punctuation: /:/,
|
---|
52 | path: /[\s\S]+/
|
---|
53 | }
|
---|
54 | },
|
---|
55 | bash: {
|
---|
56 | pattern: /(^[$#%]\s*)\S[\s\S]*/,
|
---|
57 | lookbehind: true,
|
---|
58 | alias: 'language-bash',
|
---|
59 | inside: Prism.languages.bash
|
---|
60 | },
|
---|
61 | 'shell-symbol': {
|
---|
62 | pattern: /^[$#%]/,
|
---|
63 | alias: 'important'
|
---|
64 | }
|
---|
65 | }
|
---|
66 | },
|
---|
67 | output: /.(?:.*(?:[\r\n]|.$))*/
|
---|
68 | }
|
---|
69 | Prism.languages['sh-session'] = Prism.languages['shellsession'] =
|
---|
70 | Prism.languages['shell-session']
|
---|
71 | })(Prism)
|
---|
72 | }
|
---|