Skip to content

Commit

Permalink
Shell-session: Added support for the percent sign as shell symbol (#3010
Browse files Browse the repository at this point in the history
)
  • Loading branch information
knu committed Jul 26, 2021
1 parent b38fc89 commit 4492b62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions components/prism-shell-session.js
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
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

0 comments on commit 4492b62

Please sign in to comment.