aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-10-21 17:54:21 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-10-21 17:54:21 +0200
commite556a1beb73f5d5608d7a8bad0a0c13fd148ed0a (patch)
treeec9e3ee225a17f1523115f3be47660981549fc57
parentecfebde6ffbf8fa3184a74cb685ec340ee87291a (diff)
nix develop: Handle 'declare -ax' in bash output
Fixes 'nix develop nixpkgs#qpdfview'.
-rw-r--r--src/nix/develop.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index 380417c82..32669414b 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -39,21 +39,24 @@ BuildEnvironment readEnvironment(const Path & path)
static std::string varNameRegex =
R"re((?:[a-zA-Z_][a-zA-Z0-9_]*))re";
- static std::regex declareRegex(
- "^declare -x (" + varNameRegex + ")" +
- R"re((?:="((?:[^"\\]|\\.)*)")?\n)re");
-
static std::string simpleStringRegex =
R"re((?:[a-zA-Z0-9_/:\.\-\+=]*))re";
- static std::string quotedStringRegex =
+ static std::string dquotedStringRegex =
+ R"re((?:\$?"(?:[^"\\]|\\[$`"\\\n])*"))re";
+
+ static std::string squotedStringRegex =
R"re((?:\$?'(?:[^'\\]|\\[abeEfnrtv\\'"?])*'))re";
static std::string indexedArrayRegex =
R"re((?:\(( *\[[0-9]+\]="(?:[^"\\]|\\.)*")*\)))re";
+ static std::regex declareRegex(
+ "^declare -a?x (" + varNameRegex + ")(=(" +
+ dquotedStringRegex + "|" + indexedArrayRegex + "))?\n");
+
static std::regex varRegex(
- "^(" + varNameRegex + ")=(" + simpleStringRegex + "|" + quotedStringRegex + "|" + indexedArrayRegex + ")\n");
+ "^(" + varNameRegex + ")=(" + simpleStringRegex + "|" + squotedStringRegex + "|" + indexedArrayRegex + ")\n");
/* Note: we distinguish between an indexed and associative array
using the space before the closing parenthesis. Will