| 1 |
import { l as languages } from "../../index-C1_GGQ8y.js"; |
| 2 |
var envVars = "\\b(?:BASH(?:OPTS|_ALIASES|_ARG[CV]|_CMDS|_COMPLETION_COMPAT_DIR|_LINENO|_REMATCH|_SOURCE|_VERSINFO|_VERSION)?|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|E?UID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_(?:ADDRESS|ALL|IDENTIFICATION|MEASUREMENT|MONETARY|NAME|NUMERIC|PAPER|TELEPHONE|TIME)|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS[1-4]|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_(?:CONFIG_DIRS|CURRENT_DESKTOP|DATA_DIRS|GREETER_DATA_DIR|MENU_PREFIX|RUNTIME_DIR|SEAT|SEAT_PATH|SESSION_DESKTOP|SESSION_ID|SESSION_PATH|SESSION_TYPE|VTNR)|XMODIFIERS)\\b"; |
| 3 |
var commandAfterHeredoc = { |
| 4 |
pattern: /(^(["']?)\w+\2)[ ]+\S.*/, |
| 5 |
lookbehind: true, |
| 6 |
alias: "punctuation" |
| 7 |
// this looks reasonably well in all themes |
| 8 |
}; |
| 9 |
var variableInside = { |
| 10 |
"variable": /^\$\(|^`|\)$|`$/ |
| 11 |
}; |
| 12 |
var insideString = { |
| 13 |
"bash": commandAfterHeredoc, |
| 14 |
"environment": { |
| 15 |
pattern: RegExp("\\$" + envVars), |
| 16 |
alias: "constant" |
| 17 |
}, |
| 18 |
"variable": [ |
| 19 |
// [0]: Arithmetic Environment |
| 20 |
{ |
| 21 |
pattern: /\$?\(\([^]*?\)\)/g, |
| 22 |
greedy: true, |
| 23 |
inside: { |
| 24 |
// If there is a $ sign at the beginning highlight $(( and )) as variable |
| 25 |
"variable": [ |
| 26 |
{ |
| 27 |
pattern: /(^\$[^]+)../, |
| 28 |
lookbehind: true |
| 29 |
}, |
| 30 |
/^\$\(\(/ |
| 31 |
], |
| 32 |
"number": /\b0x[a-fA-F\d]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/, |
| 33 |
// Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic |
| 34 |
"operator": /--|\+\+|&&|\|\||(?:\*\*|<<|>>|[%&|^!=<>/*+-])=?|[?:~]/, |
| 35 |
// If there is no $ sign at the beginning highlight (( and )) as punctuation |
| 36 |
"punctuation": /\(\(?|\)\)?|,|;/ |
| 37 |
} |
| 38 |
}, |
| 39 |
// [1]: Command Substitution |
| 40 |
{ |
| 41 |
pattern: /\$\((?:[^()]|\([^)]*\))*\)|`[^`]+`/g, |
| 42 |
greedy: true, |
| 43 |
inside: variableInside |
| 44 |
}, |
| 45 |
// [2]: Brace expansion |
| 46 |
{ |
| 47 |
pattern: /\$\{[^}]*\}/g, |
| 48 |
greedy: true, |
| 49 |
inside: { |
| 50 |
"operator": /:[?=+-]?|[!/]|##?|%%?|\^\^?|,,?/, |
| 51 |
"punctuation": /[[\]]/, |
| 52 |
"environment": { |
| 53 |
pattern: RegExp("(\\{)" + envVars), |
| 54 |
lookbehind: true, |
| 55 |
alias: "constant" |
| 56 |
} |
| 57 |
} |
| 58 |
}, |
| 59 |
/\$(?:\w+|[#?*!@$])/ |
| 60 |
], |
| 61 |
// Escape sequences from echo and printf's manuals, and escaped quotes. |
| 62 |
"entity": /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[a-fA-F\d]{8}|u[a-fA-F\d]{4}|x[a-fA-F\d]{1,2})/ |
| 63 |
}; |
| 64 |
var bash = commandAfterHeredoc.inside = languages.sh = languages.shell = languages.bash = { |
| 65 |
"shebang": { |
| 66 |
pattern: /^#!\s*\/.*/, |
| 67 |
alias: "important" |
| 68 |
}, |
| 69 |
"comment": { |
| 70 |
pattern: /(^|[^\\"{$])#.*/, |
| 71 |
lookbehind: true |
| 72 |
}, |
| 73 |
"function-name": [ |
| 74 |
// a) function foo { |
| 75 |
// b) foo() { |
| 76 |
// c) function foo() { |
| 77 |
// but not “foo {” |
| 78 |
{ |
| 79 |
// a) and c) |
| 80 |
pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/, |
| 81 |
lookbehind: true, |
| 82 |
alias: "function" |
| 83 |
}, |
| 84 |
{ |
| 85 |
// b) |
| 86 |
pattern: /\b[\w-]+(?=\s*\(\s*\)\s*\{)/, |
| 87 |
alias: "function" |
| 88 |
} |
| 89 |
], |
| 90 |
// Highlight variable names as variables in for and select beginnings. |
| 91 |
"for-or-select": { |
| 92 |
pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/, |
| 93 |
lookbehind: true, |
| 94 |
alias: "variable" |
| 95 |
}, |
| 96 |
// Highlight variable names as variables in the left-hand part |
| 97 |
// of assignments (“=” and “+=”). |
| 98 |
"assign-left": { |
| 99 |
pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/, |
| 100 |
lookbehind: true, |
| 101 |
alias: "variable", |
| 102 |
inside: { |
| 103 |
"environment": { |
| 104 |
pattern: RegExp("(^|[\\s;|&]|[<>]\\()" + envVars), |
| 105 |
lookbehind: true, |
| 106 |
alias: "constant" |
| 107 |
} |
| 108 |
} |
| 109 |
}, |
| 110 |
// Highlight parameter names as variables |
| 111 |
"parameter": { |
| 112 |
pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?![^\s=])/, |
| 113 |
lookbehind: true, |
| 114 |
alias: "variable" |
| 115 |
}, |
| 116 |
"string": [ |
| 117 |
// Support for Here-documents https://en.wikipedia.org/wiki/Here_document |
| 118 |
{ |
| 119 |
pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[^]*?\n\2/g, |
| 120 |
lookbehind: true, |
| 121 |
greedy: true, |
| 122 |
inside: insideString |
| 123 |
}, |
| 124 |
// Here-document with quotes around the tag |
| 125 |
// → No expansion (so no “inside”). |
| 126 |
{ |
| 127 |
pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[^]*?\n\3/g, |
| 128 |
lookbehind: true, |
| 129 |
greedy: true, |
| 130 |
inside: { |
| 131 |
"bash": commandAfterHeredoc |
| 132 |
} |
| 133 |
}, |
| 134 |
// “Normal” string |
| 135 |
{ |
| 136 |
// https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html |
| 137 |
pattern: /(^|[^\\](?:\\\\)*)"(?:\\[^]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^\\"`$])*"/g, |
| 138 |
lookbehind: true, |
| 139 |
greedy: true, |
| 140 |
inside: insideString |
| 141 |
}, |
| 142 |
{ |
| 143 |
// https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html |
| 144 |
pattern: /(^|[^\\$])'[^']*'/g, |
| 145 |
lookbehind: true, |
| 146 |
greedy: true |
| 147 |
}, |
| 148 |
{ |
| 149 |
// https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html |
| 150 |
pattern: /\$'(?:\\[^]|[^\\'])*'/g, |
| 151 |
greedy: true, |
| 152 |
inside: { |
| 153 |
"entity": insideString.entity |
| 154 |
} |
| 155 |
} |
| 156 |
], |
| 157 |
"environment": { |
| 158 |
pattern: RegExp("\\$?" + envVars), |
| 159 |
alias: "constant" |
| 160 |
}, |
| 161 |
"variable": insideString.variable, |
| 162 |
"function": { |
| 163 |
pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|c?fdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cron|crontab|c?split|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff3?|dig|dircolors|dirname|dirs?|dmesg|docker|docker-compose|du|[ef]?grep|eject|env|ethtool|expand|expect|expr|fdformat|fg|file|find|fmt|fold|format|free|fsck|fuser|g?awk|git|g?parted|groupadd|groupdel|groupmod|groups|grub-mkconfig|halt|head|hg|history|host|hostname|iconv|id|ifconfig|ifdown|ifup|import|install|ip|java|jobs|join|killall|less|link|ln|logname|logrotate|look|lpc|lprint[dq]?|lprm?|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mm?v|more|most|mtools|m?tr|mutt|nano|nc|netstat|nice|nl|node|nohup|notify-send|nslookup|op|open|passwd|paste|pathchk|ping|p?kill|p?npm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ra[mr]|reboot|remsync|rename|renice|rev|rmdir|rp?m|r?sync|[sr]?cp|screen|sdiff|se[dq]|sendmail|service|s?ftp|shellcheck|shuf|shutdown|sleep|s?locate|[sz]?sh|stat|strace|sudo|sum?|suspend|swapon|sysctl|tac|tail|tar|tee|time|timeout|h?top|touch|traceroute|t?sort|tty|u?mount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vim?|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|g?zip|zsh|zypper)(?=$|[)\s;|&])/, |
| 164 |
lookbehind: true |
| 165 |
}, |
| 166 |
"keyword": { |
| 167 |
pattern: /(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/, |
| 168 |
lookbehind: true |
| 169 |
}, |
| 170 |
// https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html |
| 171 |
"builtin": { |
| 172 |
pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|[ls]et|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/, |
| 173 |
lookbehind: true, |
| 174 |
// Alias added to make those easier to distinguish from strings. |
| 175 |
alias: "class-name" |
| 176 |
}, |
| 177 |
"boolean": { |
| 178 |
pattern: /(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/, |
| 179 |
lookbehind: true |
| 180 |
}, |
| 181 |
"file-descriptor": { |
| 182 |
pattern: /\B&\d\b/, |
| 183 |
alias: "important" |
| 184 |
}, |
| 185 |
"operator": { |
| 186 |
// Lots of redirections here, but not just that. |
| 187 |
pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/, |
| 188 |
inside: { |
| 189 |
"file-descriptor": { |
| 190 |
pattern: /^\d/, |
| 191 |
alias: "important" |
| 192 |
} |
| 193 |
} |
| 194 |
}, |
| 195 |
"punctuation": /\$?\(\(?|\)\)?|\.\.|[[\]{};\\]/, |
| 196 |
"number": { |
| 197 |
pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/, |
| 198 |
lookbehind: true |
| 199 |
} |
| 200 |
}; |
| 201 |
[ |
| 202 |
"comment", |
| 203 |
"function-name", |
| 204 |
"for-or-select", |
| 205 |
"assign-left", |
| 206 |
"parameter", |
| 207 |
"string", |
| 208 |
"environment", |
| 209 |
"function", |
| 210 |
"keyword", |
| 211 |
"builtin", |
| 212 |
"boolean", |
| 213 |
"file-descriptor", |
| 214 |
"operator", |
| 215 |
"punctuation", |
| 216 |
"number" |
| 217 |
].forEach((copied) => variableInside[copied] = bash[copied]); |
| 218 |
//# sourceMappingURL=bash.js.map |