Skip to content

Instantly share code, notes, and snippets.

@ramsaylanier
Created February 20, 2018 20:05
Show Gist options
  • Select an option

  • Save ramsaylanier/79c5ca428d3b75f7b72494e4aadcaf6d to your computer and use it in GitHub Desktop.

Select an option

Save ramsaylanier/79c5ca428d3b75f7b72494e4aadcaf6d to your computer and use it in GitHub Desktop.
Visual Studio Code extension that creates anonymous gist from higlighted text
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) {
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