Last active
August 29, 2015 14:14
-
-
Save Naatan/944d154f256558728c41 to your computer and use it in GitHub Desktop.
Komodo Macro - Open current file location on github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var notify = require("notify/notify"); | |
var editor = require("ko/editor"); | |
/* Quickly thrown together, only supports Komodo 9 and GitHub */ | |
var koDoc = ko.views.manager.currentView.koDoc; | |
if ( ! koDoc || ! koDoc.file) return; | |
var uri = koDoc.file.URI; | |
var sccSvc = ko.scc.getServiceForUrl(uri); | |
sccSvc.getKnownRemotes(uri, function(result, uris) | |
{ | |
if (result != Ci.koIAsyncCallback.RESULT_SUCCESSFUL || ! uris || ! uris.length) | |
{ | |
notify.send("Failed receiving known remotes", "macros", {priority: "error"}); | |
return; | |
} | |
var uri = uris[0][0]; | |
uri = uri.replace("[email protected]:", "https://github.com/"); | |
if (uri.endsWith(".git")) | |
uri = uri.substr(0, uri.length - 4) + "/"; | |
uri += "blob/master/"; | |
// Remove any prefix, like "ssh://" | |
if (uri.indexOf("://github.com/")) | |
uri = uri.replace(/(.*?)(https:\/\/github.com\/)/, "$2"); | |
if (uri.indexOf("git@") === 0) | |
uri = uri.substr(4).replace(":","/"); | |
var path = koDoc.file.path; | |
sccSvc.getRoot(koDoc.file.URI, function(result, repoPath) | |
{ | |
if (result != Ci.koIAsyncCallback.RESULT_SUCCESSFUL || ! repoPath) | |
{ | |
notify.send("Failed receiving repo path", "macros", {priority: "error"}); | |
return; | |
} | |
if (path.indexOf(repoPath) !== 0) | |
{ | |
notify.send("Invalid file path (doesnt match repo root path)", "macros", {priority: "error"}); | |
return; | |
} | |
path = path.substr(repoPath.length); | |
uri += path; | |
uri += "#L" + editor.getCursorPosition().line; | |
ko.browse.openUrlInDefaultBrowser(uri); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment