Skip to content

Instantly share code, notes, and snippets.

@zacjones93
Created January 29, 2021 16:48
Show Gist options
  • Save zacjones93/803f5ff5dee0a2a0fdb52f8391ceb076 to your computer and use it in GitHub Desktop.
Save zacjones93/803f5ff5dee0a2a0fdb52f8391ceb076 to your computer and use it in GitHub Desktop.
// Menu: Gist from Finder
// Description: Select a file in Finder, then create a Gist
// Author: John Lindquist
// Twitter: @johnlindquist
let filePath = await getSelectedFile()
let file = filePath.split('/').pop()
let isPublic = await arg('Should the gist be public?', {
type: 'confirm',
})
const body = {
files: {
[file]: {
content: await readFile(filePath, 'utf8'),
},
},
public: isPublic,
}
let config = {
headers: {
Authorization:
'Bearer ' +
(await env('GITHUB_GIST_TOKEN', {
info: `Create a gist token: <a class="bg-white" href="https://github.com/settings/tokens/new">https://github.com/settings/tokens/new</a>`,
message: `Set .env GITHUB_GIST_TOKEN:`,
})),
},
}
const response = await post(`https://api.github.com/gists`, body, config)
exec(`open ` + response.data.html_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment