From 3dd7ef5425a132d49bc6769f5b1ef169260e272b Mon Sep 17 00:00:00 2001 From: Brady Holt Date: Fri, 4 Dec 2015 13:27:46 -0600 Subject: [PATCH 1/2] Add open.js --- src/open.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/open.js diff --git a/src/open.js b/src/open.js new file mode 100644 index 0000000..86a2bb9 --- /dev/null +++ b/src/open.js @@ -0,0 +1,65 @@ +# https://www.npmjs.com/package/open + +var exec = require('child_process').exec + , path = require('path') + ; + + +/** + * open a file or uri using the default application for the file type. + * + * @return {ChildProcess} - the child process object. + * @param {string} target - the file/uri to open. + * @param {string} appName - (optional) the application to be used to open the + * file (for example, "chrome", "firefox") + * @param {function(Error)} callback - called with null on success, or + * an error object that contains a property 'code' with the exit + * code of the process. + */ + +module.exports = open; + +function open(target, appName, callback) { + var opener; + + if (typeof(appName) === 'function') { + callback = appName; + appName = null; + } + + switch (process.platform) { + case 'darwin': + if (appName) { + opener = 'open -a "' + escape(appName) + '"'; + } else { + opener = 'open'; + } + break; + case 'win32': + // if the first parameter to start is quoted, it uses that as the title + // so we pass a blank title so we can quote the file we are opening + if (appName) { + opener = 'start "" "' + escape(appName) + '"'; + } else { + opener = 'start ""'; + } + break; + default: + if (appName) { + opener = escape(appName); + } else { + // use Portlands xdg-open everywhere else + opener = path.join(__dirname, '../vendor/xdg-open'); + } + break; + } + + if (process.env.SUDO_USER) { + opener = 'sudo -u ' + process.env.SUDO_USER + ' ' + opener; + } + return exec(opener + ' "' + escape(target) + '"', callback); +} + +function escape(s) { + return s.replace(/"/g, '\\\"'); +} From b04a97040be3fa8be788478f61f1fd68f8f6a792 Mon Sep 17 00:00:00 2001 From: Brady Holt Date: Fri, 4 Dec 2015 13:38:22 -0600 Subject: [PATCH 2/2] Use open module to open in browser --- src/extension.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/extension.js b/src/extension.js index be69b41..efdbf58 100644 --- a/src/extension.js +++ b/src/extension.js @@ -12,6 +12,7 @@ var fs = require('fs'); var git = require('parse-git-config'); var exec = require('child_process').exec; var parse = require('github-url-from-git'); +var open = require('./open'); function findBranch(config) { for (var prop in config) { @@ -54,7 +55,7 @@ function openInGitHub() { githubLink = parsedUri + "/blob/" + branch + subdir + "#L" + lineIndex; } - exec("start " + githubLink); + open(githubLink); }); }