-
Notifications
You must be signed in to change notification settings - Fork 908
/
Copy pathcreate-github-gist.sh
executable file
·48 lines (37 loc) · 1.4 KB
/
create-github-gist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
##################################################################
## Set GitHub username and personal access token and uncomment. ##
##################################################################
# GitHub username
# user=
# GitHub personal access token
# access_key=
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Create GitHub Gist from clipboard
# @raycast.mode compact
# Optional parameters:
# @raycast.author Caleb Stauffer
# @raycast.authorURL https://github.com/crstauf
# @raycast.description Create a GitHub Gist from clipboard contents and copy Gist URL.
# @raycast.packageName GitHub
# @raycast.needsConfirmation true
# @raycast.icon images/github-logo.png
if [ -z ${user+x} ]; then
echo "GitHub username is missing.";
exit 1;
fi
if [ -z ${access_key+x} ]; then
echo "GitHub personal access token is missing.";
exit 1;
fi
if ! command -v jq &> /dev/null; then
echo "jq is required (https://stedolan.github.io/jq/).";
exit 1;
fi
clipboard=$(pbpaste)
gist_content="$( jq -nc --arg str "$clipboard" '{ "public": false, "files": { "gistfile1.txt": { "content": $str } } }' )"
auth=$(echo -n "$user:$access_key" | base64)
response=$( curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic $auth" https://api.github.com/gists -d "$gist_content" )
echo "$response" | jq -r '.html_url' | pbcopy
echo "Created gist and copied URL"