Created
January 29, 2021 16:48
-
-
Save zacjones93/803f5ff5dee0a2a0fdb52f8391ceb076 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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