Skip to content

Commit

Permalink
Bash: Added support for parameters and the java and sysctl comman…
Browse files Browse the repository at this point in the history
…ds. (#3505)

Co-authored-by: Michael Schmidt <[email protected]>
  • Loading branch information
wangliang181230 and RunDevelopment authored Jul 25, 2022
1 parent b0c2a9b commit b9512b2
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 14 deletions.
11 changes: 9 additions & 2 deletions components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
// Highlight variable names as variables in the left-hand part
// of assignments (“=” and “+=”).
'assign-left': {
pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/,
inside: {
'environment': {
pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars),
Expand All @@ -113,6 +113,12 @@
alias: 'variable',
lookbehind: true
},
// Highlight parameter names as variables
'parameter': {
pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,
alias: 'variable',
lookbehind: true
},
'string': [
// Support for Here-documents https://en.wikipedia.org/wiki/Here_document
{
Expand Down Expand Up @@ -160,7 +166,7 @@
},
'variable': insideString.variable,
'function': {
pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,
pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|java|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|sysctl|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,
lookbehind: true
},
'keyword': {
Expand Down Expand Up @@ -207,6 +213,7 @@
'function-name',
'for-or-select',
'assign-left',
'parameter',
'string',
'environment',
'function',
Expand Down
2 changes: 1 addition & 1 deletion components/prism-bash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/languages/arturo!+shell/sh-string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
["string", "{!sh"],
["embedded", [
["function", "ls"],
" -la test/*x\r\n"
["parameter", "-la"],
" test/*x\r\n"
]],
["string", "}"]
]]
Expand Down
6 changes: 4 additions & 2 deletions tests/languages/bash/function_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ ifup
import
install
ip
java
jobs
join
kill
Expand Down Expand Up @@ -198,6 +199,7 @@ sum
suspend
swapon
sync
sysctl
tac
tail
tar
Expand Down Expand Up @@ -283,7 +285,7 @@ zypper
["function", "host"], ["function", "hostname"], ["function", "htop"],
["function", "iconv"], ["function", "id"], ["function", "ifconfig"],
["function", "ifdown"], ["function", "ifup"], ["function", "import"],
["function", "install"], ["function", "ip"], ["function", "jobs"],
["function", "install"], ["function", "ip"], ["function", "java"], ["function", "jobs"],
["function", "join"], ["function", "kill"], ["function", "killall"],
["function", "less"], ["function", "link"], ["function", "ln"],
["function", "locate"], ["function", "logname"], ["function", "logrotate"],
Expand Down Expand Up @@ -317,7 +319,7 @@ zypper
["function", "slocate"], ["function", "sort"], ["function", "split"],
["function", "ssh"], ["function", "stat"], ["function", "strace"],
["function", "su"], ["function", "sudo"], ["function", "sum"], ["function",
"suspend"], ["function", "swapon"], ["function", "sync"], ["function",
"suspend"], ["function", "swapon"], ["function", "sync"], ["function", "sysctl"], ["function",
"tac"], ["function", "tail"], ["function", "tar"], ["function", "tee"],
["function", "time"], ["function", "timeout"], ["function", "top"],
["function", "touch"], ["function", "tr"], ["function", "traceroute"],
Expand Down
40 changes: 40 additions & 0 deletions tests/languages/bash/parameter_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
docker run
--name elk \
-p 5601:5601 \
--restart=always \
--privileged \
-dit \
easyj/elk:7.12.1

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

[
["function", "docker"],
" run\r\n",

["parameter", "--name"],
" elk ",
["punctuation", "\\"],

["parameter", "-p"],
["number", "5601"],
":5601 ",
["punctuation", "\\"],

["parameter", "--restart"],
["operator", ["="]],
"always ",
["punctuation", "\\"],

["parameter", "--privileged"],
["punctuation", "\\"],

["parameter", "-dit"],
["punctuation", "\\"],

"\r\neasyj/elk:7.12.1"
]

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

Checks for variable assignments.
4 changes: 2 additions & 2 deletions tests/languages/shell-session/command_string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ y_#!$U48
["operator", ["="]],
"C ",
["function", "tr"],
" -cd ",
["parameter", "-cd"],
["string", "'a-zA-Z0-9_-;:!?.@\\\\*/#%$'"],
["operator", ["<"]],
" /dev/random ",
["operator", ["|"]],
["function", "head"],
" -c ",
["parameter", "-c"],
["number", "8"]
]]
]],
Expand Down
10 changes: 6 additions & 4 deletions tests/languages/shell-session/info_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ foo@bar% exit
" ~"
]]
]],

["command", [
["info", [
["user", "foo@bar"],
Expand All @@ -31,9 +32,10 @@ foo@bar% exit
["shell-symbol", "$"],
["bash", [
["function", "sudo"],
" -i"
["parameter", "-i"]
]]
]],

["output", "[sudo] password for foo:\r\n"],
["command", [
["info", [
Expand All @@ -44,11 +46,10 @@ foo@bar% exit
["shell-symbol", "#"],
["bash", [
["builtin", "echo"],
["string", [
"\"hello!\""
]]
["string", ["\"hello!\""]]
]]
]],

["output", "hello!\r\n\r\n"],
["command", [
["info", [
Expand All @@ -59,6 +60,7 @@ foo@bar% exit
["function", "zsh"]
]]
]],

["command", [
["info", [
["user", "foo@bar"]
Expand Down
3 changes: 2 additions & 1 deletion tests/languages/shell-session/issue2644.test
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Write down the passphrase. Store both at safe place(s).
["command", [
["shell-symbol", "$"],
["bash", [
"borg init --encryption",
"borg init ",
["parameter", "--encryption"],
["operator", ["="]],
"keyfile-blake2 ",
["string", ["\"[email protected]:backup\""]]
Expand Down
3 changes: 2 additions & 1 deletion tests/languages/shell-session/issue2871.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ hello
["bash", [
["function", "sudo"],
["function", "ls"],
" -l ~/.config ",
["parameter", "-l"],
" ~/.config ",
["string", "'s'"],
["operator", ["&&"]],
["punctuation", "\\"],
Expand Down

0 comments on commit b9512b2

Please sign in to comment.