let filePath = await getSelectedFile()
let file = filePath.split("/").pop()
let isPublic = await arg("Should the gist be public?", [
{ name: "No", value: false },
{ name: "Yes", value: true },
])
const body = {
files: {
[file]: {
content: await readFile(filePath, "utf8"),
},
},
}
if (isPublic) body.public = true
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)