Created
February 20, 2018 20:57
-
-
Save ramsaylanier/4887fef783373a90f2289b68714ad664 to your computer and use it in GitHub Desktop.
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
const vscode = require("vscode"); | |
const editor = vscode.window.activeTextEditor; | |
const rp = require("request-promise"); | |
async function CreateGist() { | |
const text = editor.document.getText(editor.selection); | |
// User Input to name Gist file | |
const gistName = await vscode.window.showInputBox({ | |
placeHolder: "Name Your GistTest" | |
}); | |
const options = { | |
method: "POST", | |
uri: "https://api.github.com/gists", | |
headers: { | |
"User-Agent": "Request-Promise" | |
}, | |
body: { | |
description: "the description for this gist", | |
public: true, | |
files: {} | |
}, | |
json: true | |
}; | |
options.body.files[gistName] = { content: text }; | |
rp(options).then(r => { | |
const parsedUrl = vscode.Uri.parse(r.html_url); | |
vscode.commands.executeCommand("vscode.open", parsedUrl); | |
}); | |
} | |
function activate(context) { | |
// this code runs whenever your click 'Create Gist' from the context menu in your browser. | |
let disposable = vscode.commands.registerCommand( | |
"extension.createGist", | |
function() { | |
CreateGist(); | |
} | |
); | |
context.subscriptions.push(disposable); | |
} | |
exports.activate = activate; | |
function deactivate() {} | |
exports.deactivate = deactivate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment