Skip to content

Commit 7d10f7f

Browse files
authored
enh(bash) added gnu core utilities (#3344)
* enh(bash) add gnu core utilities Co-authored-by: Josh Goebel <[email protected]> * prevent false positive on paths * just forget about install for now, far too common an argument * (chore) reorganization keywords
1 parent 934f2e7 commit 7d10f7f

File tree

7 files changed

+247
-24
lines changed

7 files changed

+247
-24
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Grammars:
2424
- enh(scala) add `inline` soft keyword (#3329) [Nicolas Stucki][]
2525
- enh(scala) add `using` soft keyword (#3330) [Nicolas Stucki][]
2626
- enh(fsharp) added `f#` alias (#3337) [Bahnschrift][]
27+
- enh(bash) added gnu core utilities (#3342) [katzeprior][]
2728

2829
[Austin Schick]: https://github.com/austin-schick
2930
[Josh Goebel]: https://github.com/joshgoebel
@@ -32,6 +33,7 @@ Grammars:
3233
[Teletha]: https://github.com/teletha
3334
[Nicolas Stucki]: https://github.com/nicolasstucki
3435
[Bahnschrift]: https://github.com/Bahnschrift
36+
[katzeprior]: https://github.com/katzeprior
3537

3638

3739
## Version 11.2.0

src/languages/bash.js

Lines changed: 237 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,250 @@ export default function(hljs) {
122122
"false"
123123
];
124124

125+
// to consume paths to prevent keyword matches inside them
126+
const PATH_MODE = {
127+
match: /(\/[a-z._-]+)+/
128+
};
129+
130+
// http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
131+
const SHELL_BUILT_INS = [
132+
"break",
133+
"cd",
134+
"continue",
135+
"eval",
136+
"exec",
137+
"exit",
138+
"export",
139+
"getopts",
140+
"hash",
141+
"pwd",
142+
"readonly",
143+
"return",
144+
"shift",
145+
"test",
146+
"times",
147+
"trap",
148+
"umask",
149+
"unset"
150+
];
151+
152+
const BASH_BUILT_INS = [
153+
"alias",
154+
"bind",
155+
"builtin",
156+
"caller",
157+
"command",
158+
"declare",
159+
"echo",
160+
"enable",
161+
"help",
162+
"let",
163+
"local",
164+
"logout",
165+
"mapfile",
166+
"printf",
167+
"read",
168+
"readarray",
169+
"source",
170+
"type",
171+
"typeset",
172+
"ulimit",
173+
"unalias"
174+
];
175+
176+
const ZSH_BUILT_INS = [
177+
"autoload",
178+
"bg",
179+
"bindkey",
180+
"bye",
181+
"cap",
182+
"chdir",
183+
"clone",
184+
"comparguments",
185+
"compcall",
186+
"compctl",
187+
"compdescribe",
188+
"compfiles",
189+
"compgroups",
190+
"compquote",
191+
"comptags",
192+
"comptry",
193+
"compvalues",
194+
"dirs",
195+
"disable",
196+
"disown",
197+
"echotc",
198+
"echoti",
199+
"emulate",
200+
"fc",
201+
"fg",
202+
"float",
203+
"functions",
204+
"getcap",
205+
"getln",
206+
"history",
207+
"integer",
208+
"jobs",
209+
"kill",
210+
"limit",
211+
"log",
212+
"noglob",
213+
"popd",
214+
"print",
215+
"pushd",
216+
"pushln",
217+
"rehash",
218+
"sched",
219+
"setcap",
220+
"setopt",
221+
"stat",
222+
"suspend",
223+
"ttyctl",
224+
"unfunction",
225+
"unhash",
226+
"unlimit",
227+
"unsetopt",
228+
"vared",
229+
"wait",
230+
"whence",
231+
"where",
232+
"which",
233+
"zcompile",
234+
"zformat",
235+
"zftp",
236+
"zle",
237+
"zmodload",
238+
"zparseopts",
239+
"zprof",
240+
"zpty",
241+
"zregexparse",
242+
"zsocket",
243+
"zstyle",
244+
"ztcp"
245+
];
246+
247+
const GNU_CORE_UTILS = [
248+
"chcon",
249+
"chgrp",
250+
"chown",
251+
"chmod",
252+
"cp",
253+
"dd",
254+
"df",
255+
"dir",
256+
"dircolors",
257+
"ln",
258+
"ls",
259+
"mkdir",
260+
"mkfifo",
261+
"mknod",
262+
"mktemp",
263+
"mv",
264+
"realpath",
265+
"rm",
266+
"rmdir",
267+
"shred",
268+
"sync",
269+
"touch",
270+
"truncate",
271+
"vdir",
272+
"b2sum",
273+
"base32",
274+
"base64",
275+
"cat",
276+
"cksum",
277+
"comm",
278+
"csplit",
279+
"cut",
280+
"expand",
281+
"fmt",
282+
"fold",
283+
"head",
284+
"join",
285+
"md5sum",
286+
"nl",
287+
"numfmt",
288+
"od",
289+
"paste",
290+
"ptx",
291+
"pr",
292+
"sha1sum",
293+
"sha224sum",
294+
"sha256sum",
295+
"sha384sum",
296+
"sha512sum",
297+
"shuf",
298+
"sort",
299+
"split",
300+
"sum",
301+
"tac",
302+
"tail",
303+
"tr",
304+
"tsort",
305+
"unexpand",
306+
"uniq",
307+
"wc",
308+
"arch",
309+
"basename",
310+
"chroot",
311+
"date",
312+
"dirname",
313+
"du",
314+
"echo",
315+
"env",
316+
"expr",
317+
"factor",
318+
// "false", // keyword literal already
319+
"groups",
320+
"hostid",
321+
"id",
322+
"link",
323+
"logname",
324+
"nice",
325+
"nohup",
326+
"nproc",
327+
"pathchk",
328+
"pinky",
329+
"printenv",
330+
"printf",
331+
"pwd",
332+
"readlink",
333+
"runcon",
334+
"seq",
335+
"sleep",
336+
"stat",
337+
"stdbuf",
338+
"stty",
339+
"tee",
340+
"test",
341+
"timeout",
342+
// "true", // keyword literal already
343+
"tty",
344+
"uname",
345+
"unlink",
346+
"uptime",
347+
"users",
348+
"who",
349+
"whoami",
350+
"yes"
351+
];
352+
125353
return {
126354
name: 'Bash',
127355
aliases: ['sh'],
128356
keywords: {
129357
$pattern: /\b[a-z._-]+\b/,
130358
keyword: KEYWORDS,
131359
literal: LITERALS,
132-
built_in:
133-
// Shell built-ins
134-
// http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
135-
'break cd continue eval exec exit export getopts hash pwd readonly return shift test times ' +
136-
'trap umask unset ' +
137-
// Bash built-ins
138-
'alias bind builtin caller command declare echo enable help let local logout mapfile printf ' +
139-
'read readarray source type typeset ulimit unalias ' +
360+
built_in:[
361+
...SHELL_BUILT_INS,
362+
...BASH_BUILT_INS,
140363
// Shell modifiers
141-
'set shopt ' +
142-
// Zsh built-ins
143-
'autoload bg bindkey bye cap chdir clone comparguments compcall compctl compdescribe compfiles ' +
144-
'compgroups compquote comptags comptry compvalues dirs disable disown echotc echoti emulate ' +
145-
'fc fg float functions getcap getln history integer jobs kill limit log noglob popd print ' +
146-
'pushd pushln rehash sched setcap setopt stat suspend ttyctl unfunction unhash unlimit ' +
147-
'unsetopt vared wait whence where which zcompile zformat zftp zle zmodload zparseopts zprof ' +
148-
'zpty zregexparse zsocket zstyle ztcp'
364+
"set",
365+
"shopt",
366+
...ZSH_BUILT_INS,
367+
...GNU_CORE_UTILS
368+
]
149369
},
150370
contains: [
151371
KNOWN_SHEBANG, // to catch known shells and boost relevancy
@@ -154,6 +374,7 @@ export default function(hljs) {
154374
ARITHMETIC,
155375
hljs.HASH_COMMENT_MODE,
156376
HERE_DOC,
377+
PATH_MODE,
157378
QUOTE_STRING,
158379
ESCAPED_QUOTE,
159380
APOS_STRING,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<span class="hljs-comment"># Escaped double-quote is not a string</span>
2-
<span class="hljs-built_in">echo</span> <span class="hljs-string">&#x27;&quot;quoted&quot;&#x27;</span> | tr -d \&quot; &gt; text.txt
2+
<span class="hljs-built_in">echo</span> <span class="hljs-string">&#x27;&quot;quoted&quot;&#x27;</span> | <span class="hljs-built_in">tr</span> -d \&quot; &gt; text.txt
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<span class="hljs-comment"># numbers aren&#x27;t highlighted in bash as their semantics is</span>
22
<span class="hljs-comment"># not strictly defined for command line parameters</span>
3-
$ tail -10 access.log
3+
$ <span class="hljs-built_in">tail</span> -10 access.log

test/markup/bash/strings.expect.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ EOF</span>
88

99
jshell -s - &lt;&lt;&lt;<span class="hljs-string">&#x27;System.out.printf(&quot;Procs: %s%n&quot;, getdata())&#x27;</span>
1010

11-
cat &lt;&lt;&lt; <span class="hljs-string">&#x27;$VARIABLE&#x27;</span>
12-
cat &lt;&lt;&lt; <span class="hljs-string">&quot;<span class="hljs-variable">$VARIABLE</span>&quot;</span>
13-
cat &lt;&lt;&lt; <span class="hljs-variable">$VARIABLE</span>
14-
cat &lt;&lt;&lt; `<span class="hljs-variable">$VARIABLE</span>`
11+
<span class="hljs-built_in">cat</span> &lt;&lt;&lt; <span class="hljs-string">&#x27;$VARIABLE&#x27;</span>
12+
<span class="hljs-built_in">cat</span> &lt;&lt;&lt; <span class="hljs-string">&quot;<span class="hljs-variable">$VARIABLE</span>&quot;</span>
13+
<span class="hljs-built_in">cat</span> &lt;&lt;&lt; <span class="hljs-variable">$VARIABLE</span>
14+
<span class="hljs-built_in">cat</span> &lt;&lt;&lt; `<span class="hljs-variable">$VARIABLE</span>`

test/markup/dockerfile/default.expect.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<span class="hljs-keyword">RUN</span><span class="language-bash"> apt-get update \
1010
&amp;&amp; apt-get install -y php5-fpm php-apc php5-curl php5-gd php5-intl php5-mysql</span>
11-
<span class="hljs-keyword">RUN</span><span class="language-bash"> mkdir /tmp/sessions</span>
11+
<span class="hljs-keyword">RUN</span><span class="language-bash"> <span class="hljs-built_in">mkdir</span> /tmp/sessions</span>
1212

1313
<span class="hljs-keyword">ENV</span> APPLICATION_ENV dev
1414

test/markup/shell/command-continuation.expect.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
--group-add=<span class="hljs-variable">$groups</span> \
99
neo4j:3.4</span>
1010
<span class="hljs-meta">&gt; </span><span class="language-bash">/bin/cat \.travis.yml\
11-
-b | head -n1</span>
11+
-b | <span class="hljs-built_in">head</span> -n1</span>
1212
1 language: node_js
1313
<span class="hljs-meta">&gt; </span><span class="language-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">&#x27;hello&#x27;</span></span>
1414
hello

0 commit comments

Comments
 (0)