From 4d8ab3530e72d195bb2e134db4ce4575f474dc26 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 18 Oct 2008 14:21:21 +0000 Subject: [PATCH] expand brace notation (${VAR}) environment variables in pathnames --- content/io.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/content/io.js b/content/io.js index ce4a7fd8..2c8001ff 100644 --- a/content/io.js +++ b/content/io.js @@ -426,20 +426,12 @@ function IO() //{{{ path = path.replace("~", home); } - // expand any $ENV vars - var envVars = path.match(/\$\w+\b/g); // this is naive but so is Vim and we like to be compatible - - if (envVars) - { - var expansion; - - for (let i = 0; i < envVars.length; i++) - { - expansion = environmentService.get(envVars[i].replace("$", "")); - if (expansion) - path = path.replace(envVars[i], expansion); - } - } + // expand any $ENV vars - this is naive but so is Vim and we like to be compatible + // TODO: Vim does not expand variables set to an empty string - are we just matching a bug? + path = path.replace( + /\$(?:{\w+}|\w+\b)/g, + function (v) environmentService.get(v.replace(/\${?(\w+)}?/, "$1")) || v + ); return path; },