Shell-Session: Improvements (#2208)
- Added support for elevated shells starting commands with `#` instead of `$`. - The user and cwd info `bash` and `sh` print before the interactive shell will now be highlighted. - Changed the line ends of test files to CRLF.
This commit is contained in:
parent
15983d5297
commit
bd16bd5755
|
@ -18,25 +18,37 @@
|
|||
].join('|');
|
||||
|
||||
Prism.languages['shell-session'] = {
|
||||
'info': {
|
||||
// foo@bar:~/files$ exit
|
||||
// foo@bar$ exit
|
||||
pattern: /^(?:[^\r\n$#*!]+)(?=[$#])/m,
|
||||
alias: 'punctuation',
|
||||
inside: {
|
||||
'path': {
|
||||
pattern: /(:)[\s\S]+/,
|
||||
lookbehind: true
|
||||
},
|
||||
'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,
|
||||
'punctuation': /:/
|
||||
}
|
||||
},
|
||||
'command': {
|
||||
pattern: RegExp(/\$(?:[^\r\n'"<]|<<str>>)+/.source.replace(/<<str>>/g, strings)),
|
||||
pattern: RegExp(/[$#](?:[^\r\n'"<]|<<str>>)+/.source.replace(/<<str>>/g, strings)),
|
||||
greedy: true,
|
||||
inside: {
|
||||
'bash': {
|
||||
pattern: /(\$\s*)[\s\S]+/,
|
||||
pattern: /(^[$#]\s*)[\s\S]+/,
|
||||
lookbehind: true,
|
||||
alias: 'language-bash',
|
||||
inside: Prism.languages.bash
|
||||
},
|
||||
'sh': {
|
||||
pattern: /^\$/,
|
||||
'shell-symbol': {
|
||||
pattern: /^[$#]/,
|
||||
alias: 'important'
|
||||
}
|
||||
}
|
||||
},
|
||||
'output': {
|
||||
pattern: /.(?:.*(?:\r\n?|\n|.$))*/
|
||||
// output highlighting?
|
||||
}
|
||||
'output': /.(?:.*(?:\r\n?|\n|.$))*/
|
||||
};
|
||||
|
||||
}(Prism));
|
||||
|
|
|
@ -1 +1 @@
|
|||
!function(s){var n=["([\"'])(?:\\\\[\\s\\S]|\\$\\([^)]+\\)|`[^`]+`|(?!\\1)[^\\\\])*\\1","<<-?\\s*(\\w+?)\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\2","<<-?\\s*([\"'])(\\w+)\\3\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\4"].join("|");s.languages["shell-session"]={command:{pattern:RegExp("\\$(?:[^\r\\n'\"<]|<<str>>)+".replace(/<<str>>/g,n)),inside:{bash:{pattern:/(\$\s*)[\s\S]+/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},sh:{pattern:/^\$/,alias:"important"}}},output:{pattern:/.(?:.*(?:\r\n?|\n|.$))*/}}}(Prism);
|
||||
!function(s){var n=["([\"'])(?:\\\\[\\s\\S]|\\$\\([^)]+\\)|`[^`]+`|(?!\\1)[^\\\\])*\\1","<<-?\\s*(\\w+?)\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\2","<<-?\\s*([\"'])(\\w+)\\3\\s*(?:\r?\n|\r)[\\s\\S]*?(?:\r?\n|\r)\\4"].join("|");s.languages["shell-session"]={info:{pattern:/^(?:[^\r\n$#*!]+)(?=[$#])/m,alias:"punctuation",inside:{path:{pattern:/(:)[\s\S]+/,lookbehind:!0},user:/^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,punctuation:/:/}},command:{pattern:RegExp("[$#](?:[^\r\\n'\"<]|<<str>>)+".replace(/<<str>>/g,n)),greedy:!0,inside:{bash:{pattern:/(^[$#]\s*)[\s\S]+/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#]/,alias:"important"}}},output:/.(?:.*(?:\r\n?|\n|.$))*/}}(Prism);
|
|
@ -8,3 +8,11 @@ $ echo "Foo
|
|||
> Bar"
|
||||
Foo
|
||||
Bar</code></pre>
|
||||
|
||||
<p><code class="language-none">bash</code> and <code class="language-none">sh</code> console sessions are fully supported.</p>
|
||||
|
||||
<pre><code>foo@bar:/$ cd ~
|
||||
foo@bar:~$ sudo -i
|
||||
[sudo] password for foo:
|
||||
root@bar:~# echo "hello!"
|
||||
hello!</code></pre>
|
||||
|
|
|
@ -1,31 +1,44 @@
|
|||
$ git checkout master
|
||||
Switched to branch 'master'
|
||||
Your branch is up-to-date with 'origin/master'.
|
||||
$ git push
|
||||
Everything up-to-date
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["command", [
|
||||
["sh", "$"],
|
||||
["bash", [
|
||||
["function", "git"],
|
||||
" checkout master"
|
||||
]]
|
||||
]],
|
||||
["output", "Switched to branch 'master'\nYour branch is up-to-date with 'origin/master'.\n"],
|
||||
|
||||
["command", [
|
||||
["sh", "$"],
|
||||
["bash", [
|
||||
["function", "git"],
|
||||
" push"
|
||||
]]
|
||||
]],
|
||||
["output", "Everything up-to-date"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for commands.
|
||||
$ git checkout master
|
||||
Switched to branch 'master'
|
||||
Your branch is up-to-date with 'origin/master'.
|
||||
$ git push
|
||||
Everything up-to-date
|
||||
# echo "root"
|
||||
root
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["function", "git"],
|
||||
" checkout master"
|
||||
]]
|
||||
]],
|
||||
["output", "Switched to branch 'master'\r\nYour branch is up-to-date with 'origin/master'.\r\n"],
|
||||
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["function", "git"],
|
||||
" push"
|
||||
]]
|
||||
]],
|
||||
["output", "Everything up-to-date\r\n"],
|
||||
|
||||
["command", [
|
||||
["shell-symbol", "#"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["string", [
|
||||
"\"root\""
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
["output", "root"]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for commands.
|
||||
|
|
|
@ -1,66 +1,66 @@
|
|||
$ echo 'Foo
|
||||
> Bar'
|
||||
$ echo "Foo
|
||||
> Bar"
|
||||
|
||||
$ echo <<- STRING_END
|
||||
foo
|
||||
bar
|
||||
STRING_END
|
||||
|
||||
$ echo <<- "STRING_END"
|
||||
foo
|
||||
bar
|
||||
STRING_END
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["command", [
|
||||
["sh", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["string", [
|
||||
"'Foo\n> Bar'"
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
|
||||
["command", [
|
||||
["sh", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["string", [
|
||||
"\"Foo\n> Bar\""
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
|
||||
["command", [
|
||||
["sh", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["operator", [
|
||||
"<<-"
|
||||
]],
|
||||
["string", [
|
||||
"STRING_END\nfoo\nbar\nSTRING_END"
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
|
||||
["command", [
|
||||
["sh", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["operator", [
|
||||
"<<-"
|
||||
]],
|
||||
["string", "\"STRING_END\"\nfoo\nbar\nSTRING_END"]
|
||||
]]
|
||||
]]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for multi-line strings inside commands.
|
||||
$ echo 'Foo
|
||||
> Bar'
|
||||
$ echo "Foo
|
||||
> Bar"
|
||||
|
||||
$ echo <<- STRING_END
|
||||
foo
|
||||
bar
|
||||
STRING_END
|
||||
|
||||
$ echo <<- "STRING_END"
|
||||
foo
|
||||
bar
|
||||
STRING_END
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["string", [
|
||||
"'Foo\r\n> Bar'"
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["string", [
|
||||
"\"Foo\r\n> Bar\""
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["operator", [
|
||||
"<<-"
|
||||
]],
|
||||
["string", [
|
||||
"STRING_END\r\nfoo\r\nbar\r\nSTRING_END"
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["operator", [
|
||||
"<<-"
|
||||
]],
|
||||
["string", "\"STRING_END\"\r\nfoo\r\nbar\r\nSTRING_END"]
|
||||
]]
|
||||
]]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for multi-line strings inside commands.
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
foo@bar:/var/local$ cd ~
|
||||
foo@bar:~$ sudo -i
|
||||
[sudo] password for foo:
|
||||
root@bar:~# echo "hello!"
|
||||
hello!
|
||||
|
||||
foo@bar$ exit
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["info", [
|
||||
["user", "foo@bar"],
|
||||
["punctuation", ":"],
|
||||
["path", "/var/local"]
|
||||
]],
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["builtin", "cd"],
|
||||
" ~"
|
||||
]]
|
||||
]],
|
||||
|
||||
["info", [
|
||||
["user", "foo@bar"],
|
||||
["punctuation", ":"],
|
||||
["path", "~"]
|
||||
]],
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["function", "sudo"],
|
||||
" -i"
|
||||
]]
|
||||
]],
|
||||
["output", "[sudo] password for foo:\r\n"],
|
||||
|
||||
["info", [
|
||||
["user", "root@bar"],
|
||||
["punctuation", ":"],
|
||||
["path", "~"]
|
||||
]],
|
||||
["command", [
|
||||
["shell-symbol", "#"],
|
||||
["bash", [
|
||||
["builtin", "echo"],
|
||||
["string", [
|
||||
"\"hello!\""
|
||||
]]
|
||||
]]
|
||||
]],
|
||||
["output", "hello!\r\n\r\n"],
|
||||
|
||||
["info", [
|
||||
["user", "foo@bar"]
|
||||
]],
|
||||
["command", [
|
||||
["shell-symbol", "$"],
|
||||
["bash", [
|
||||
["builtin", "exit"]
|
||||
]]
|
||||
]]
|
||||
]
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
Checks for the info bash outputs.
|
Loading…
Reference in New Issue