diff --git a/src/js/cmdline.js b/src/js/cmdline.js index b852f99..0a2cc74 100644 --- a/src/js/cmdline.js +++ b/src/js/cmdline.js @@ -47,7 +47,7 @@ for(var i = 1; i < ARGV.length; i++) { if(pmake.options[args[0]]) { var opts = pmake.options[args[0]].options; - var opt = pmake.options[args[0]].option; + var opt = pmake.options[args[0]].option; if(opts) { if((typeof opts) == "function") opts = opts(); @@ -60,7 +60,7 @@ for(var i = 1; i < ARGV.length; i++) { console.log("Error: invalid value '" + args[1] + "' for option '" + args[0] + "'"); process.exit(1); } else if(opts || opt) { - pmake.options[args[0]].action(args[1]); + pmake.options[args[0]].action(args[1].replace(/^~(\/?)/, fs.home + "$1")); } else { pmake.options[args[0]].action(); } diff --git a/src/js_fs.c b/src/js_fs.c index 2cffc64..1be98c1 100644 --- a/src/js_fs.c +++ b/src/js_fs.c @@ -107,6 +107,19 @@ static duk_ret_t js_fs_cwd(duk_context* self) { void js_fs_init(void) { int obj; char started_cwd[1024]; + char home[1024]; +#ifndef _WIN32 + struct passwd* p; +#endif + + home[0] = 0; + +#ifdef _WIN32 + strcpy(home, getenv("USERPROFILE")); +#else + p = getpwuid(getuid()); + strcpy(home, p->pw_dir); +#endif getcwd(started_cwd, 1024); @@ -130,5 +143,8 @@ void js_fs_init(void) { duk_push_string(js_ctx, started_cwd); duk_put_prop_string(js_ctx, obj, "startedCwd"); + duk_push_string(js_ctx, home); + duk_put_prop_string(js_ctx, obj, "home"); + duk_put_prop_string(js_ctx, 0, "fs"); } diff --git a/src/pmake.h b/src/pmake.h index 9978e87..b7a1894 100644 --- a/src/pmake.h +++ b/src/pmake.h @@ -11,6 +11,7 @@ #include #else #include +#include #endif #include