From ae62af34c17b342f84200f3b04ec9f44c70e193c Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sun, 10 Jun 2007 11:16:32 +0000 Subject: [PATCH] translate ~ to HOME on Windows for use with :source --- chrome/content/vimperator/commands.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index a07c30e6..83f31260 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -1594,6 +1594,33 @@ function source(filename, silent) if (!filename) return; + function getEnv(variable) + { + var environment = Components.classes["@mozilla.org/process/environment;1"] + .getService(Components.interfaces.nsIEnvironment); + return environment.get(variable); + } + + // convert "~" to HOME on Windows + if (navigator.platform == "Win32") + { + // TODO: proper pathname separator translation like Vim + filename = filename.replace('/', '\\', 'g'); + var matches = filename.match(/^~(.*)/) + if (matches) + { + var home_dir = getEnv("HOME"); + if (!home_dir) + home_dir = getEnv("USERPROFILE"); + if (!home_dir) + { + // TODO: are these guaranteed to be set? + home_dir = getEnv("HOMEDRIVE") + getEnv("HOMEPATH"); + } + filename = home_dir + "\\" + matches[1]; + } + } + try { var fd = fopen(filename, "<");