Skip to content

Commit b9512b2

Browse files
Bash: Added support for parameters and the java and sysctl commands. (#3505)
Co-authored-by: Michael Schmidt <[email protected]>
1 parent b0c2a9b commit b9512b2

9 files changed

+68
-14
lines changed

components/prism-bash.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
// Highlight variable names as variables in the left-hand part
103103
// of assignments (“=” and “+=”).
104104
'assign-left': {
105-
pattern: /(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,
105+
pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/,
106106
inside: {
107107
'environment': {
108108
pattern: RegExp('(^|[\\s;|&]|[<>]\\()' + envVars),
@@ -113,6 +113,12 @@
113113
alias: 'variable',
114114
lookbehind: true
115115
},
116+
// Highlight parameter names as variables
117+
'parameter': {
118+
pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,
119+
alias: 'variable',
120+
lookbehind: true
121+
},
116122
'string': [
117123
// Support for Here-documents https://en.wikipedia.org/wiki/Here_document
118124
{
@@ -160,7 +166,7 @@
160166
},
161167
'variable': insideString.variable,
162168
'function': {
163-
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;|&])/,
169+
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;|&])/,
164170
lookbehind: true
165171
},
166172
'keyword': {
@@ -207,6 +213,7 @@
207213
'function-name',
208214
'for-or-select',
209215
'assign-left',
216+
'parameter',
210217
'string',
211218
'environment',
212219
'function',

components/prism-bash.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/arturo!+shell/sh-string_feature.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
["string", "{!sh"],
1010
["embedded", [
1111
["function", "ls"],
12-
" -la test/*x\r\n"
12+
["parameter", "-la"],
13+
" test/*x\r\n"
1314
]],
1415
["string", "}"]
1516
]]

tests/languages/bash/function_feature.test

+4-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ ifup
9393
import
9494
install
9595
ip
96+
java
9697
jobs
9798
join
9899
kill
@@ -198,6 +199,7 @@ sum
198199
suspend
199200
swapon
200201
sync
202+
sysctl
201203
tac
202204
tail
203205
tar
@@ -283,7 +285,7 @@ zypper
283285
["function", "host"], ["function", "hostname"], ["function", "htop"],
284286
["function", "iconv"], ["function", "id"], ["function", "ifconfig"],
285287
["function", "ifdown"], ["function", "ifup"], ["function", "import"],
286-
["function", "install"], ["function", "ip"], ["function", "jobs"],
288+
["function", "install"], ["function", "ip"], ["function", "java"], ["function", "jobs"],
287289
["function", "join"], ["function", "kill"], ["function", "killall"],
288290
["function", "less"], ["function", "link"], ["function", "ln"],
289291
["function", "locate"], ["function", "logname"], ["function", "logrotate"],
@@ -317,7 +319,7 @@ zypper
317319
["function", "slocate"], ["function", "sort"], ["function", "split"],
318320
["function", "ssh"], ["function", "stat"], ["function", "strace"],
319321
["function", "su"], ["function", "sudo"], ["function", "sum"], ["function",
320-
"suspend"], ["function", "swapon"], ["function", "sync"], ["function",
322+
"suspend"], ["function", "swapon"], ["function", "sync"], ["function", "sysctl"], ["function",
321323
"tac"], ["function", "tail"], ["function", "tar"], ["function", "tee"],
322324
["function", "time"], ["function", "timeout"], ["function", "top"],
323325
["function", "touch"], ["function", "tr"], ["function", "traceroute"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
docker run
2+
--name elk \
3+
-p 5601:5601 \
4+
--restart=always \
5+
--privileged \
6+
-dit \
7+
easyj/elk:7.12.1
8+
9+
----------------------------------------------------
10+
11+
[
12+
["function", "docker"],
13+
" run\r\n",
14+
15+
["parameter", "--name"],
16+
" elk ",
17+
["punctuation", "\\"],
18+
19+
["parameter", "-p"],
20+
["number", "5601"],
21+
":5601 ",
22+
["punctuation", "\\"],
23+
24+
["parameter", "--restart"],
25+
["operator", ["="]],
26+
"always ",
27+
["punctuation", "\\"],
28+
29+
["parameter", "--privileged"],
30+
["punctuation", "\\"],
31+
32+
["parameter", "-dit"],
33+
["punctuation", "\\"],
34+
35+
"\r\neasyj/elk:7.12.1"
36+
]
37+
38+
----------------------------------------------------
39+
40+
Checks for variable assignments.

tests/languages/shell-session/command_string_feature.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ y_#!$U48
9797
["operator", ["="]],
9898
"C ",
9999
["function", "tr"],
100-
" -cd ",
100+
["parameter", "-cd"],
101101
["string", "'a-zA-Z0-9_-;:!?.@\\\\*/#%$'"],
102102
["operator", ["<"]],
103103
" /dev/random ",
104104
["operator", ["|"]],
105105
["function", "head"],
106-
" -c ",
106+
["parameter", "-c"],
107107
["number", "8"]
108108
]]
109109
]],

tests/languages/shell-session/info_feature.test

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ foo@bar% exit
2222
" ~"
2323
]]
2424
]],
25+
2526
["command", [
2627
["info", [
2728
["user", "foo@bar"],
@@ -31,9 +32,10 @@ foo@bar% exit
3132
["shell-symbol", "$"],
3233
["bash", [
3334
["function", "sudo"],
34-
" -i"
35+
["parameter", "-i"]
3536
]]
3637
]],
38+
3739
["output", "[sudo] password for foo:\r\n"],
3840
["command", [
3941
["info", [
@@ -44,11 +46,10 @@ foo@bar% exit
4446
["shell-symbol", "#"],
4547
["bash", [
4648
["builtin", "echo"],
47-
["string", [
48-
"\"hello!\""
49-
]]
49+
["string", ["\"hello!\""]]
5050
]]
5151
]],
52+
5253
["output", "hello!\r\n\r\n"],
5354
["command", [
5455
["info", [
@@ -59,6 +60,7 @@ foo@bar% exit
5960
["function", "zsh"]
6061
]]
6162
]],
63+
6264
["command", [
6365
["info", [
6466
["user", "foo@bar"]

tests/languages/shell-session/issue2644.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Write down the passphrase. Store both at safe place(s).
4444
["command", [
4545
["shell-symbol", "$"],
4646
["bash", [
47-
"borg init --encryption",
47+
"borg init ",
48+
["parameter", "--encryption"],
4849
["operator", ["="]],
4950
"keyfile-blake2 ",
5051
["string", ["\"[email protected]:backup\""]]

tests/languages/shell-session/issue2871.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ hello
1515
["bash", [
1616
["function", "sudo"],
1717
["function", "ls"],
18-
" -l ~/.config ",
18+
["parameter", "-l"],
19+
" ~/.config ",
1920
["string", "'s'"],
2021
["operator", ["&&"]],
2122
["punctuation", "\\"],

0 commit comments

Comments
 (0)