diff --git a/CHANGES.md b/CHANGES.md index e44684abd4..406fe383cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -24,6 +24,7 @@ Grammars: - enh(scala) add `inline` soft keyword (#3329) [Nicolas Stucki][] - enh(scala) add `using` soft keyword (#3330) [Nicolas Stucki][] - enh(fsharp) added `f#` alias (#3337) [Bahnschrift][] +- enh(bash) added gnu core utilities (#3342) [katzeprior][] [Austin Schick]: https://github.com/austin-schick [Josh Goebel]: https://github.com/joshgoebel @@ -32,6 +33,7 @@ Grammars: [Teletha]: https://github.com/teletha [Nicolas Stucki]: https://github.com/nicolasstucki [Bahnschrift]: https://github.com/Bahnschrift +[katzeprior]: https://github.com/katzeprior ## Version 11.2.0 diff --git a/src/languages/bash.js b/src/languages/bash.js index 7106830e0f..d167aa807c 100644 --- a/src/languages/bash.js +++ b/src/languages/bash.js @@ -122,6 +122,234 @@ export default function(hljs) { "false" ]; + // to consume paths to prevent keyword matches inside them + const PATH_MODE = { + match: /(\/[a-z._-]+)+/ + }; + + // http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html + const SHELL_BUILT_INS = [ + "break", + "cd", + "continue", + "eval", + "exec", + "exit", + "export", + "getopts", + "hash", + "pwd", + "readonly", + "return", + "shift", + "test", + "times", + "trap", + "umask", + "unset" + ]; + + const BASH_BUILT_INS = [ + "alias", + "bind", + "builtin", + "caller", + "command", + "declare", + "echo", + "enable", + "help", + "let", + "local", + "logout", + "mapfile", + "printf", + "read", + "readarray", + "source", + "type", + "typeset", + "ulimit", + "unalias" + ]; + + const ZSH_BUILT_INS = [ + "autoload", + "bg", + "bindkey", + "bye", + "cap", + "chdir", + "clone", + "comparguments", + "compcall", + "compctl", + "compdescribe", + "compfiles", + "compgroups", + "compquote", + "comptags", + "comptry", + "compvalues", + "dirs", + "disable", + "disown", + "echotc", + "echoti", + "emulate", + "fc", + "fg", + "float", + "functions", + "getcap", + "getln", + "history", + "integer", + "jobs", + "kill", + "limit", + "log", + "noglob", + "popd", + "print", + "pushd", + "pushln", + "rehash", + "sched", + "setcap", + "setopt", + "stat", + "suspend", + "ttyctl", + "unfunction", + "unhash", + "unlimit", + "unsetopt", + "vared", + "wait", + "whence", + "where", + "which", + "zcompile", + "zformat", + "zftp", + "zle", + "zmodload", + "zparseopts", + "zprof", + "zpty", + "zregexparse", + "zsocket", + "zstyle", + "ztcp" + ]; + + const GNU_CORE_UTILS = [ + "chcon", + "chgrp", + "chown", + "chmod", + "cp", + "dd", + "df", + "dir", + "dircolors", + "ln", + "ls", + "mkdir", + "mkfifo", + "mknod", + "mktemp", + "mv", + "realpath", + "rm", + "rmdir", + "shred", + "sync", + "touch", + "truncate", + "vdir", + "b2sum", + "base32", + "base64", + "cat", + "cksum", + "comm", + "csplit", + "cut", + "expand", + "fmt", + "fold", + "head", + "join", + "md5sum", + "nl", + "numfmt", + "od", + "paste", + "ptx", + "pr", + "sha1sum", + "sha224sum", + "sha256sum", + "sha384sum", + "sha512sum", + "shuf", + "sort", + "split", + "sum", + "tac", + "tail", + "tr", + "tsort", + "unexpand", + "uniq", + "wc", + "arch", + "basename", + "chroot", + "date", + "dirname", + "du", + "echo", + "env", + "expr", + "factor", + // "false", // keyword literal already + "groups", + "hostid", + "id", + "link", + "logname", + "nice", + "nohup", + "nproc", + "pathchk", + "pinky", + "printenv", + "printf", + "pwd", + "readlink", + "runcon", + "seq", + "sleep", + "stat", + "stdbuf", + "stty", + "tee", + "test", + "timeout", + // "true", // keyword literal already + "tty", + "uname", + "unlink", + "uptime", + "users", + "who", + "whoami", + "yes" + ]; + return { name: 'Bash', aliases: ['sh'], @@ -129,23 +357,15 @@ export default function(hljs) { $pattern: /\b[a-z._-]+\b/, keyword: KEYWORDS, literal: LITERALS, - built_in: - // Shell built-ins - // http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html - 'break cd continue eval exec exit export getopts hash pwd readonly return shift test times ' + - 'trap umask unset ' + - // Bash built-ins - 'alias bind builtin caller command declare echo enable help let local logout mapfile printf ' + - 'read readarray source type typeset ulimit unalias ' + + built_in:[ + ...SHELL_BUILT_INS, + ...BASH_BUILT_INS, // Shell modifiers - 'set shopt ' + - // Zsh built-ins - 'autoload bg bindkey bye cap chdir clone comparguments compcall compctl compdescribe compfiles ' + - 'compgroups compquote comptags comptry compvalues dirs disable disown echotc echoti emulate ' + - 'fc fg float functions getcap getln history integer jobs kill limit log noglob popd print ' + - 'pushd pushln rehash sched setcap setopt stat suspend ttyctl unfunction unhash unlimit ' + - 'unsetopt vared wait whence where which zcompile zformat zftp zle zmodload zparseopts zprof ' + - 'zpty zregexparse zsocket zstyle ztcp' + "set", + "shopt", + ...ZSH_BUILT_INS, + ...GNU_CORE_UTILS + ] }, contains: [ KNOWN_SHEBANG, // to catch known shells and boost relevancy @@ -154,6 +374,7 @@ export default function(hljs) { ARITHMETIC, hljs.HASH_COMMENT_MODE, HERE_DOC, + PATH_MODE, QUOTE_STRING, ESCAPED_QUOTE, APOS_STRING, diff --git a/test/markup/bash/escaped-quote.expect.txt b/test/markup/bash/escaped-quote.expect.txt index 72b2f0c5c2..3d7f2432ae 100644 --- a/test/markup/bash/escaped-quote.expect.txt +++ b/test/markup/bash/escaped-quote.expect.txt @@ -1,2 +1,2 @@ # Escaped double-quote is not a string -echo '"quoted"' | tr -d \" > text.txt +echo '"quoted"' | tr -d \" > text.txt diff --git a/test/markup/bash/no-numbers.expect.txt b/test/markup/bash/no-numbers.expect.txt index 5b96c2855b..258f5d74b7 100644 --- a/test/markup/bash/no-numbers.expect.txt +++ b/test/markup/bash/no-numbers.expect.txt @@ -1,3 +1,3 @@ # numbers aren't highlighted in bash as their semantics is # not strictly defined for command line parameters -$ tail -10 access.log +$ tail -10 access.log diff --git a/test/markup/bash/strings.expect.txt b/test/markup/bash/strings.expect.txt index e2715c2fc6..b86c42b509 100644 --- a/test/markup/bash/strings.expect.txt +++ b/test/markup/bash/strings.expect.txt @@ -8,7 +8,7 @@ EOF jshell -s - <<<'System.out.printf("Procs: %s%n", getdata())' -cat <<< '$VARIABLE' -cat <<< "$VARIABLE" -cat <<< $VARIABLE -cat <<< `$VARIABLE` +cat <<< '$VARIABLE' +cat <<< "$VARIABLE" +cat <<< $VARIABLE +cat <<< `$VARIABLE` diff --git a/test/markup/dockerfile/default.expect.txt b/test/markup/dockerfile/default.expect.txt index 9f673f5db3..a3aafcb9a0 100644 --- a/test/markup/dockerfile/default.expect.txt +++ b/test/markup/dockerfile/default.expect.txt @@ -8,7 +8,7 @@ RUN apt-get update \ && apt-get install -y php5-fpm php-apc php5-curl php5-gd php5-intl php5-mysql -RUN mkdir /tmp/sessions +RUN mkdir /tmp/sessions ENV APPLICATION_ENV dev diff --git a/test/markup/shell/command-continuation.expect.txt b/test/markup/shell/command-continuation.expect.txt index cf9861e6fe..96639a632d 100644 --- a/test/markup/shell/command-continuation.expect.txt +++ b/test/markup/shell/command-continuation.expect.txt @@ -8,7 +8,7 @@ --group-add=$groups \ neo4j:3.4 > /bin/cat \.travis.yml\ - -b | head -n1 + -b | head -n1 1 language: node_js > echo 'hello' hello