Skip to content

Commit

Permalink
Merge pull request #10 from bradyholt/master
Browse files Browse the repository at this point in the history
Allow cross platform ability
  • Loading branch information
bugthesystem committed Dec 4, 2015
2 parents b91d612 + b04a970 commit fafdd0b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -54,7 +55,7 @@ function openInGitHub() {
githubLink = parsedUri + "/blob/" + branch + subdir + "#L" + lineIndex;
}

exec("start " + githubLink);
open(githubLink);
});
}

Expand Down
65 changes: 65 additions & 0 deletions src/open.js
Original file line number Diff line number Diff line change
@@ -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, '\\\"');
}

0 comments on commit fafdd0b

Please sign in to comment.