Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the percent sign as shell symbol #3010

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions components/prism-shell-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
}
}
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.

12 changes: 11 additions & 1 deletion tests/languages/shell-session/info_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ foo@bar:~$ sudo -i
root@bar:~# echo "hello!"
hello!

foo@bar$ exit
foo@bar$ zsh
foo@bar% exit

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

Expand Down Expand Up @@ -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"]
]]
Expand Down