Skip to content

Instantly share code, notes, and snippets.

@rubeniskov
Last active May 14, 2022 17:03
Show Gist options
  • Save rubeniskov/09fb6a27aba0335b9c521ecd0e6d201d to your computer and use it in GitHub Desktop.
Save rubeniskov/09fb6a27aba0335b9c521ecd0e6d201d to your computer and use it in GitHub Desktop.
Makefile publish gist snippet
# $(call publish_gist,<access_token>,<filename>,<description>[,gist_hash])
define publish_gist
cat $(2) |\
awk -v description="$(3)" \
-v filename="$(2)" \
'BEGIN {\
ORS = "";\
print("{");\
printf("\"description\": \"%s\",",description);\
printf("\"public\": %s,","true");\
print("\"files\": {");\
printf("\"%s\": {",filename);\
print("\"content\": \"");\
} { \
gsub(/\\/, "\\\\", $$0);\
gsub(/"/, "\\\"", $$0);\
printf("%s\\n", $$0);\
} END { \
print("\"}}}"); \
}' |\
curl 'https://api.github.com/gists/$(4)?access_token=$(1)' \
--request POST \
--header "Content-Type: application/json" \
--data @- 2>/dev/null |\
grep 'raw_url' |\
awk -F'"' '{print "remote_url "$$4}'
endef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment