From 277040f2f434c6f5b9ab038d5e41332b99e09bb3 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Mon, 26 Jul 2021 12:20:49 +0900 Subject: [PATCH] Add support for the percent sign as shell symbol It is used by (t)csh and zsh. --- components/prism-shell-session.js | 12 ++++++------ components/prism-shell-session.min.js | 2 +- tests/languages/shell-session/info_feature.test | 12 +++++++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/prism-shell-session.js b/components/prism-shell-session.js index 39da49fa59..9ec763fdec 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?)|\$(?!')|<>)+/.source.replace(/<>/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 89e5d85bdb..208c65f865 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?)|\\$(?!')|<>)+".replace(/<>/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?)|\\$(?!')|<>)+".replace(/<>/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 fbb6e4b2b1..f8cf93d500 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 ---------------------------------------------------- @@ -54,6 +55,15 @@ foo@bar$ exit ["user", "foo@bar"] ]], ["shell-symbol", "$"], + ["bash", [ + ["function", "zsh"] + ]] + ]], + ["command", [ + ["info", [ + ["user", "foo@bar"] + ]], + ["shell-symbol", "%"], ["bash", [ ["builtin", "exit"] ]]