Skip to content

Commit

Permalink
Add support for the percent sign as shell symbol
Browse files Browse the repository at this point in the history
It is used by (t)csh and zsh.
  • Loading branch information
knu committed Jul 26, 2021
1 parent b38fc89 commit 2ba8cad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
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
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

0 comments on commit 2ba8cad

Please sign in to comment.