Bash: Added support for parameters and the `java` and `sysctl` commands. (#3505)

Co-authored-by: Michael Schmidt <msrd0000@gmail.com>
This commit is contained in:
WangLiang/王良 2022-07-25 21:24:17 +08:00 committed by GitHub
parent b0c2a9b4a7
commit b9512b221e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 68 additions and 14 deletions

View File

@ -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),
@ -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
{
@ -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': {
@ -207,6 +213,7 @@
'function-name',
'for-or-select',
'assign-left',
'parameter',
'string',
'environment',
'function',

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,8 @@
["string", "{!sh"],
["embedded", [
["function", "ls"],
" -la test/*x\r\n"
["parameter", "-la"],
" test/*x\r\n"
]],
["string", "}"]
]]

View File

@ -93,6 +93,7 @@ ifup
import
install
ip
java
jobs
join
kill
@ -198,6 +199,7 @@ sum
suspend
swapon
sync
sysctl
tac
tail
tar
@ -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"],
@ -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"],

View File

@ -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.

View File

@ -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"]
]]
]],

View File

@ -22,6 +22,7 @@ foo@bar% exit
" ~"
]]
]],
["command", [
["info", [
["user", "foo@bar"],
@ -31,9 +32,10 @@ foo@bar% exit
["shell-symbol", "$"],
["bash", [
["function", "sudo"],
" -i"
["parameter", "-i"]
]]
]],
["output", "[sudo] password for foo:\r\n"],
["command", [
["info", [
@ -44,11 +46,10 @@ foo@bar% exit
["shell-symbol", "#"],
["bash", [
["builtin", "echo"],
["string", [
"\"hello!\""
]]
["string", ["\"hello!\""]]
]]
]],
["output", "hello!\r\n\r\n"],
["command", [
["info", [
@ -59,6 +60,7 @@ foo@bar% exit
["function", "zsh"]
]]
]],
["command", [
["info", [
["user", "foo@bar"]

View File

@ -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", ["\"borg@1.2.3.4:backup\""]]

View File

@ -15,7 +15,8 @@ hello
["bash", [
["function", "sudo"],
["function", "ls"],
" -l ~/.config ",
["parameter", "-l"],
" ~/.config ",
["string", "'s'"],
["operator", ["&&"]],
["punctuation", "\\"],