diff --git a/bin/c9 b/bin/c9 index 6d325552..8ed2d891 100755 --- a/bin/c9 +++ b/bin/c9 @@ -1,8 +1,8 @@ #!/usr/bin/env node // workaround for npm 3 breaking bundled dependencies +var Module = require("module"); if (Module.REPLACE_NODE_MODULE_PATH) { - var Module = require("module"); var path = require("path") var _resolveFilename_orig = Module._resolveFilename Module._resolveFilename = function(id, parent) { diff --git a/plugins/c9.cli.bridge/bridge-client.js b/plugins/c9.cli.bridge/bridge-client.js index f27353be..c5325542 100644 --- a/plugins/c9.cli.bridge/bridge-client.js +++ b/plugins/c9.cli.bridge/bridge-client.js @@ -59,7 +59,7 @@ define(function(require, exports, module) { if (done) return; callback(new Error("No Response")); done = true; - }) + }); }); } diff --git a/plugins/c9.cli.bridge/bridge_commands.js b/plugins/c9.cli.bridge/bridge_commands.js index 1ec548ad..5e697a0a 100644 --- a/plugins/c9.cli.bridge/bridge_commands.js +++ b/plugins/c9.cli.bridge/bridge_commands.js @@ -74,20 +74,25 @@ define(function(require, exports, module) { /***** Methods *****/ function createPipe(message, callback) { tabManager.once("ready", function(){ - tabManager.open( { - focus: true, - editorType: "ace" + tabManager.open({ + focus: true, + editorType: "ace", + path: message.path && c9.toInternalPath(message.path), + document: { meta : { newfile: true } } }, function(err, tab) { if (err) return callback(err); - callback(null, tab.name); + callback(null, tab.path || tab.name); }); }); } function updatePipe(message, callback) { tabManager.once("ready", function() { - tabManager.findTab(message.tab).document.value += message.data; + var tab = tabManager.findTab(message.tab); + var c9Session = tab && tab.document.getSession(); + if (c9Session && c9Session.session) + c9Session.session.insert({row: Number.MAX_VALUE, column: Number.MAX_VALUE} , message.data); callback(null, true); }); } @@ -127,12 +132,22 @@ define(function(require, exports, module) { } else { tabManager.once("ready", function(){ + var m = /:(\d*)(?::(\d*))?$/.exec(path); + var jump = {}; + if (m) { + if (m[1]) + jump.row = parseInt(m[1], 10) - 1; + if (m[2]) + jump.column = parseInt(m[2], 10); + path = path.slice(0, m.index); + } + fs.exists(path, function(existing) { var tab = tabManager.open({ path: path, focus: i === 0, document: existing - ? undefined + ? { ace: { jump: jump } } : { meta : { newfile: true } } }, function(){ next(); diff --git a/plugins/c9.cli.open/open.js b/plugins/c9.cli.open/open.js index ecb5052a..5b8b68da 100755 --- a/plugins/c9.cli.open/open.js +++ b/plugins/c9.cli.open/open.js @@ -11,8 +11,6 @@ define(function(require, exports, module) { var fs = require("fs"); var PATH = require("path"); - var StringDecoder = require('string_decoder').StringDecoder; - var decoder = new StringDecoder("utf8"); /***** Initialization *****/ @@ -45,7 +43,7 @@ define(function(require, exports, module) { throw new Error("Missing path"); }, exec: function(argv) { - if(argv.pipe) { + if (argv.pipe) { openWithPipe(function(){}); return; } @@ -60,7 +58,6 @@ define(function(require, exports, module) { /***** Methods *****/ function open(paths, wait, callback) { - try { paths = paths.map(function(path) { var isDir = fs.existsSync(path) && fs.statSync(path).isDirectory(); @@ -139,7 +136,10 @@ define(function(require, exports, module) { } function openWithPipe(callback) { - bridge.send({ type: "pipe" }, function cb(err, response) { + bridge.send({ + type: "pipe", + path: process.cwd() + "/" + "Pipe " + (new Date()).toLocaleString().replace(/:/g, "."), + }, function cb(err, response) { if (err) { if (err.code == "ECONNREFUSED") { // Seems Cloud9 is not running, lets start it up @@ -163,12 +163,13 @@ define(function(require, exports, module) { } var stdin = process.openStdin(); + stdin.setEncoding("utf8"); var finished = 0; stdin.on("data", function(chunk) { finished++; - bridge.send( { - type: "pipeData", - data: decoder.write(chunk), + bridge.send({ + type: "pipeData", + data: chunk, tab: response }, function(err, message) { // Dunno why, but this always returns No Response... @@ -180,7 +181,7 @@ define(function(require, exports, module) { }); stdin.on("end", function() { (function retry() { - if(finished === 0) + if (finished === 0) process.exit(); setTimeout(retry, 100); })();