Last active
May 14, 2022 17:03
-
-
Save rubeniskov/09fb6a27aba0335b9c521ecd0e6d201d to your computer and use it in GitHub Desktop.
Makefile publish gist snippet
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
# $(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