diff --git a/CHANGES.md b/CHANGES.md
index 9061a346cb..b9ef99e36d 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -19,6 +19,9 @@ Language Improvements:
- fix(javascript) prevent get/set variables conflicting with keywords (#2440) [Josh Goebel][]
- bug(clojure) Now highlights `defn-` properly (#2438) [Josh Goebel][]
+- enh(bash) default value is another variable (#2439) [Josh Goebel][]
+- enh(bash) string nested within string (#2439) [Josh Goebel][]
+- enh(bash) Add arithmetic expression support (#2439) [Josh Goebel][]
- enh(clojure) Add support for global definitions name (#2347) [Alexandre Grison][]
- enh(fortran) Support Fortran 77 style comments (#2416) [Josh Goebel][]
- (csharp) add support for `@identifier` style identifiers (#2414) [Josh Goebel][]
diff --git a/src/languages/bash.js b/src/languages/bash.js
index 3d37ded159..be9c8c92fc 100644
--- a/src/languages/bash.js
+++ b/src/languages/bash.js
@@ -7,35 +7,66 @@ Category: common
*/
export default function(hljs) {
- var VAR = {
+ const VAR = {};
+ const BRACED_VAR = {
+ begin: /\$\{/, end:/\}/,
+ contains: [
+ { begin: /:-/, contains: [VAR] } // default values
+ ]
+ };
+ Object.assign(VAR,{
className: 'variable',
variants: [
{begin: /\$[\w\d#@][\w\d_]*/},
- {begin: /\$\{(.*?)}/}
+ BRACED_VAR
]
+ });
+
+ const SUBST = {
+ className: 'subst',
+ begin: /\$\(/, end: /\)/,
+ contains: [hljs.BACKSLASH_ESCAPE]
};
- var QUOTE_STRING = {
+ const QUOTE_STRING = {
className: 'string',
begin: /"/, end: /"/,
contains: [
hljs.BACKSLASH_ESCAPE,
VAR,
- {
- className: 'variable',
- begin: /\$\(/, end: /\)/,
- contains: [hljs.BACKSLASH_ESCAPE]
- }
+ SUBST
]
};
- var ESCAPED_QUOTE = {
+ SUBST.contains.push(QUOTE_STRING);
+ const ESCAPED_QUOTE = {
className: '',
begin: /\\"/
};
- var APOS_STRING = {
+ const APOS_STRING = {
className: 'string',
begin: /'/, end: /'/
};
+ const ARITHMETIC = {
+ begin: /\$\(\(/,
+ end: /\)\)/,
+ contains: [
+ { begin: /\d+#[0-9a-f]+/, className: "number" },
+ hljs.NUMBER_MODE,
+ VAR
+ ]
+ };
+ const SHEBANG = {
+ className: 'meta',
+ begin: /^#![^\n]+sh\s*$/,
+ relevance: 10
+ };
+ const FUNCTION = {
+ className: 'function',
+ begin: /\w[\w\d_]*\s*\(\s*\)\s*\{/,
+ returnBegin: true,
+ contains: [hljs.inherit(hljs.TITLE_MODE, {begin: /\w[\w\d_]*/})],
+ relevance: 0
+ };
return {
name: 'Bash',
@@ -67,18 +98,9 @@ export default function(hljs) {
'-ne -eq -lt -gt -f -d -e -s -l -a' // relevance booster
},
contains: [
- {
- className: 'meta',
- begin: /^#![^\n]+sh\s*$/,
- relevance: 10
- },
- {
- className: 'function',
- begin: /\w[\w\d_]*\s*\(\s*\)\s*\{/,
- returnBegin: true,
- contains: [hljs.inherit(hljs.TITLE_MODE, {begin: /\w[\w\d_]*/})],
- relevance: 0
- },
+ SHEBANG,
+ FUNCTION,
+ ARITHMETIC,
hljs.HASH_COMMENT_MODE,
QUOTE_STRING,
ESCAPED_QUOTE,
diff --git a/test/markup/bash/arithmetic.expect.txt b/test/markup/bash/arithmetic.expect.txt
new file mode 100644
index 0000000000..28ebd37413
--- /dev/null
+++ b/test/markup/bash/arithmetic.expect.txt
@@ -0,0 +1,8 @@
+echo $(( 16#deadbeef / 1003 ))
+
+yumi=deadbeef
+echo $(( 16#$yumi / 1003 ))
+
+B=20
+yumi=deadbeef
+echo $(( $B#$yumi / 1003 ))
diff --git a/test/markup/bash/arithmetic.txt b/test/markup/bash/arithmetic.txt
new file mode 100644
index 0000000000..d44dea465e
--- /dev/null
+++ b/test/markup/bash/arithmetic.txt
@@ -0,0 +1,8 @@
+echo $(( 16#deadbeef / 1003 ))
+
+yumi=deadbeef
+echo $(( 16#$yumi / 1003 ))
+
+B=20
+yumi=deadbeef
+echo $(( $B#$yumi / 1003 ))
diff --git a/test/markup/bash/strings.expect.txt b/test/markup/bash/strings.expect.txt
new file mode 100644
index 0000000000..39abcc1b1d
--- /dev/null
+++ b/test/markup/bash/strings.expect.txt
@@ -0,0 +1,3 @@
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+TLS_DIR="$SCRIPT_DIR/../src/main/resources/tls"
+ROOT_DIR="$SCRIPT_DIR/.."
diff --git a/test/markup/bash/strings.txt b/test/markup/bash/strings.txt
new file mode 100644
index 0000000000..c2d7f55732
--- /dev/null
+++ b/test/markup/bash/strings.txt
@@ -0,0 +1,3 @@
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+TLS_DIR="$SCRIPT_DIR/../src/main/resources/tls"
+ROOT_DIR="$SCRIPT_DIR/.."
diff --git a/test/markup/bash/variables.expect.txt b/test/markup/bash/variables.expect.txt
new file mode 100644
index 0000000000..708b15f2f2
--- /dev/null
+++ b/test/markup/bash/variables.expect.txt
@@ -0,0 +1,3 @@
+$A
+${B}
+${WURST:-${CARNE}}
diff --git a/test/markup/bash/variables.txt b/test/markup/bash/variables.txt
new file mode 100644
index 0000000000..eb89ed0cda
--- /dev/null
+++ b/test/markup/bash/variables.txt
@@ -0,0 +1,3 @@
+$A
+${B}
+${WURST:-${CARNE}}