@@ -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 ,
0 commit comments