Skip to content

Commit

Permalink
Shell session: Commands prefixed with a path are now detected (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Jan 1, 2021
1 parent 88a17b4 commit c83fd0b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
12 changes: 5 additions & 7 deletions components/prism-shell-session.js
Expand Up @@ -15,21 +15,19 @@

Prism.languages['shell-session'] = {
'command': {
pattern: RegExp(/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?)?[$#](?:[^\\\r\n'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }), 'm'),
pattern: RegExp(/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>:;|]+)?[$#](?:[^\\\r\n'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }), 'm'),
greedy: true,
inside: {
'info': {
// foo@bar:~/files$ exit
// foo@bar$ exit
// ~/files$ exit
pattern: /^[^#$]+/,
alias: 'punctuation',
inside: {
'path': {
pattern: /(:)[\s\S]+/,
lookbehind: true
},
'user': /^[^:]+/,
'punctuation': /:/
'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+/,
'punctuation': /:/,
'path': /[\s\S]+/
}
},
'bash': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-shell-session.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions tests/languages/shell-session/issue2685.test
@@ -0,0 +1,29 @@
/home/user$ echo "Hello World"
Hello World
/home/user$ exit

----------------------------------------------------

[
["command", [
["info", [
["path", "/home/user"]
]],
["shell-symbol", "$"],
["bash", [
["builtin", "echo"],
["string", ["\"Hello World\""]]
]]
]],

["output", "Hello World\r\n"],
["command", [
["info", [
["path", "/home/user"]
]],
["shell-symbol", "$"],
["bash", [
["builtin", "exit"]
]]
]]
]

0 comments on commit c83fd0b

Please sign in to comment.