mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-08 16:04:13 +01:00
Make path expansion vim compatible: expand vars before and after expanding ~. Are we matching bugs?
This commit is contained in:
@@ -409,8 +409,19 @@ function IO() //{{{
|
|||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
path = path.replace("/", "\\", "g");
|
path = path.replace("/", "\\", "g");
|
||||||
|
|
||||||
|
// 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 (and documents it).
|
||||||
|
// Kris reckons we shouldn't replicate this 'bug'. --djk
|
||||||
|
// TODO: should we be doing this for all paths?
|
||||||
|
function expand(path) path.replace(
|
||||||
|
!WINDOWS ? /\$(\w+)\b|\${(\w+)}/g
|
||||||
|
: /\$(\w+)\b|\${(\w+)}|%(\w+)%/g,
|
||||||
|
function (m, n1, n2, n3) environmentService.get(n1 || n2 || n3) || m
|
||||||
|
);
|
||||||
|
path = expand(path);
|
||||||
|
|
||||||
// expand ~
|
// expand ~
|
||||||
if (path[0] == "~")
|
if (/^~(?:$|\/)/.test(path))
|
||||||
{
|
{
|
||||||
// Try $(VIMPERATOR|MUTTATOR)_HOME || $HOME first, on all systems
|
// Try $(VIMPERATOR|MUTTATOR)_HOME || $HOME first, on all systems
|
||||||
let home = environmentService.get(config.name.toUpperCase() + "_HOME") ||
|
let home = environmentService.get(config.name.toUpperCase() + "_HOME") ||
|
||||||
@@ -424,15 +435,12 @@ function IO() //{{{
|
|||||||
path = home + path.substr(1);
|
path = home + path.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// expand any $ENV vars - this is naive but so is Vim and we like to be compatible
|
// TODO: Vim expands paths twice, once before checking for ~, once
|
||||||
// TODO: Vim does not expand variables set to an empty string (and documents it).
|
// after, but doesn't document it. Is this just a bug? --Kris
|
||||||
// Kris reckons we shouldn't replicate this 'bug'. --djk
|
path = expand(path);
|
||||||
// TODO: should we be doing this for all paths?
|
|
||||||
path = path.replace(
|
|
||||||
!WINDOWS ? /\$(\w+)\b|\${(\w+)}/g : /\$(\w+)\b|\${(\w+)}|%(\w+)%/g,
|
|
||||||
function (m, n1, n2, n3) environmentService.get(n1 || n2 || n3) || m
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// FIXME: Should we be doing this here? I think it should be done
|
||||||
|
// by the arg parser or nowhere. --Kris
|
||||||
return path.replace("\\ ", " ", "g");
|
return path.replace("\\ ", " ", "g");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user