Shell-session: Added support for the percent sign as shell symbol (#3010)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/components/prism-shell-session.js b/components/prism-shell-session.js
index 39da49f..9ec763f 100644
--- a/components/prism-shell-session.js
+++ b/components/prism-shell-session.js
@@ -18,9 +18,9 @@
'command': {
pattern: RegExp(
// user info
- /^(?:[^\s@:$#*!/\\]+@[^\r\n@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?|[^\0-\x1F$#*?"<>@:;|]+)?/.source +
+ /^(?:[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+(?::[^\0-\x1F$#%*?"<>:;|]+)?|[^\0-\x1F$#%*?"<>@:;|]+)?/.source +
// shell symbol
- /[$#]/.source +
+ /[$#%]/.source +
// bash command
/(?:[^\\\r\n'"<$]|\\(?:[^\r]|\r\n?)|\$(?!')|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; }),
'm'
@@ -31,22 +31,22 @@
// foo@bar:~/files$ exit
// foo@bar$ exit
// ~/files$ exit
- pattern: /^[^#$]+/,
+ pattern: /^[^#$%]+/,
alias: 'punctuation',
inside: {
- 'user': /^[^\s@:$#*!/\\]+@[^\r\n@:$#*!/\\]+/,
+ 'user': /^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,
'punctuation': /:/,
'path': /[\s\S]+/
}
},
'bash': {
- pattern: /(^[$#]\s*)\S[\s\S]*/,
+ pattern: /(^[$#%]\s*)\S[\s\S]*/,
lookbehind: true,
alias: 'language-bash',
inside: Prism.languages.bash
},
'shell-symbol': {
- pattern: /^[$#]/,
+ pattern: /^[$#%]/,
alias: 'important'
}
}
diff --git a/components/prism-shell-session.min.js b/components/prism-shell-session.min.js
index 89e5d85..208c65f 100644
--- a/components/prism-shell-session.min.js
+++ b/components/prism-shell-session.min.js
@@ -1 +1 @@
-!function(s){var n=['"(?:\\\\[^]|\\$\\([^)]+\\)|\\$(?!\\()|`[^`]+`|[^"\\\\`$])*"',"'[^']*'","\\$'(?:[^'\\\\]|\\\\[^])*'","<<-?\\s*([\"']?)(\\w+)\\1\\s[^]*?[\r\n]\\2"].join("|");s.languages["shell-session"]={command:{pattern:RegExp('^(?:[^\\s@:$#*!/\\\\]+@[^\r\n@:$#*!/\\\\]+(?::[^\0-\\x1F$#*?"<>:;|]+)?|[^\0-\\x1F$#*?"<>@:;|]+)?[$#]'+"(?:[^\\\\\r\n'\"<$]|\\\\(?:[^\r]|\r\n?)|\\$(?!')|<<str>>)+".replace(/<<str>>/g,function(){return n}),"m"),greedy:!0,inside:{info:{pattern:/^[^#$]+/,alias:"punctuation",inside:{user:/^[^\s@:$#*!/\\]+@[^\r\n@:$#*!/\\]+/,punctuation:/:/,path:/[\s\S]+/}},bash:{pattern:/(^[$#]\s*)\S[\s\S]*/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#]/,alias:"important"}}},output:/.(?:.*(?:[\r\n]|.$))*/},s.languages["sh-session"]=s.languages.shellsession=s.languages["shell-session"]}(Prism);
\ No newline at end of file
+!function(s){var n=['"(?:\\\\[^]|\\$\\([^)]+\\)|\\$(?!\\()|`[^`]+`|[^"\\\\`$])*"',"'[^']*'","\\$'(?:[^'\\\\]|\\\\[^])*'","<<-?\\s*([\"']?)(\\w+)\\1\\s[^]*?[\r\n]\\2"].join("|");s.languages["shell-session"]={command:{pattern:RegExp('^(?:[^\\s@:$#%*!/\\\\]+@[^\r\n@:$#%*!/\\\\]+(?::[^\0-\\x1F$#%*?"<>:;|]+)?|[^\0-\\x1F$#%*?"<>@:;|]+)?[$#%]'+"(?:[^\\\\\r\n'\"<$]|\\\\(?:[^\r]|\r\n?)|\\$(?!')|<<str>>)+".replace(/<<str>>/g,function(){return n}),"m"),greedy:!0,inside:{info:{pattern:/^[^#$%]+/,alias:"punctuation",inside:{user:/^[^\s@:$#%*!/\\]+@[^\r\n@:$#%*!/\\]+/,punctuation:/:/,path:/[\s\S]+/}},bash:{pattern:/(^[$#%]\s*)\S[\s\S]*/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#%]/,alias:"important"}}},output:/.(?:.*(?:[\r\n]|.$))*/},s.languages["sh-session"]=s.languages.shellsession=s.languages["shell-session"]}(Prism);
\ No newline at end of file
diff --git a/tests/languages/shell-session/info_feature.test b/tests/languages/shell-session/info_feature.test
index fbb6e4b..f8cf93d 100644
--- a/tests/languages/shell-session/info_feature.test
+++ b/tests/languages/shell-session/info_feature.test
@@ -4,7 +4,8 @@ foo@bar:~$ sudo -i
root@bar:~# echo "hello!"
hello!
-foo@bar$ exit
+foo@bar$ zsh
+foo@bar% exit
----------------------------------------------------
@@ -55,6 +56,15 @@ foo@bar$ exit
]],
["shell-symbol", "$"],
["bash", [
+ ["function", "zsh"]
+ ]]
+ ]],
+ ["command", [
+ ["info", [
+ ["user", "foo@bar"]
+ ]],
+ ["shell-symbol", "%"],
+ ["bash", [
["builtin", "exit"]
]]
]]