summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-01-27 23:43:24 +0800
committertypebrook <typebrook@gmail.com>2020-01-27 23:43:24 +0800
commit2d34e23619a39b212f4d71373323880f106f1ba9 (patch)
tree8dfd963717563de624c98d223b01256a65cdce86 /scripts/gist
parentce962ecceed7e2254f29ddf1a3a5055fced26a7b (diff)
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist18
1 files changed, 4 insertions, 14 deletions
diff --git a/scripts/gist b/scripts/gist
index f0816e5..6d58fe7 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -61,24 +61,14 @@ config=~/.config/gistrc
61set -eo pipefail 61set -eo pipefail
62[ "$TRACE" ] && set -x 62[ "$TRACE" ] && set -x
63 63
64# TODO error handling while password is not true
65# TODO support access token from input or web
66_auth() { 64_auth() {
67 local data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}"
68 read -p "Github username: " user < /dev/tty 65 read -p "Github username: " user < /dev/tty
69 read -sp "Github password: " password < /dev/tty
70 mkdir -p ~/.config && umask 0077 && echo user=$user > $config 66 mkdir -p ~/.config && umask 0077 && echo user=$user > $config
67 echo "Create a new token from web browser"
68 python -mwebbrowser https://github.com/settings/tokens/new\?scopes\=gist
71 69
72 curl -i https://api.github.com/authorizations \ 70 read -p "Paste your token here: " new_token < /dev/tty
73 --user "$user:$password" \ 71 echo token=$new_token >> $config
74 --data "$data"
75
76 read -p "2-factor code: " OTP < /dev/tty
77 curl https://api.github.com/authorizations \
78 --user "$user:$password" -H "X-GitHub-OTP: $OTP" \
79 --data "$data" \
80 | sed '1 s/[^{]//g' | jq -r .token \
81 | sed 's/^/token=/' >> $config
82} 72}
83 73
84case "$1" in 74case "$1" in