summaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gist41
1 files changed, 25 insertions, 16 deletions
diff --git a/scripts/gist b/scripts/gist
index 8f89102..3b98c24 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -55,11 +55,34 @@
55# TODO completion 55# TODO completion
56# define your environmemnts here 56# define your environmemnts here
57#------------------- 57#-------------------
58github_api_token=$(cat $SETTING_DIR/tokens/gist)
59user=typebrook
60folder=~/git/gist 58folder=~/git/gist
59config=~/.config/gist
61#------------------- 60#-------------------
62 61
62# while password is not true
63_auth() {
64 data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}"
65 read -p "Github username: " user
66 read -sp "Github password: " password
67 mkdir -p ~/.config
68 echo user=$user > $config
69
70 curl -s https://api.github.com/authorizations \
71 --user "$user:$password" \
72 --data "$data" > /dev/null
73
74 read -p "2-factor code: " OTP
75 curl -s https://api.github.com/authorizations \
76 --user "$user:$password" -H "X-GitHub-OTP: $OTP" \
77 --data "$data" |\
78 sed '1 s/[^{]//g' | jq -r .token |\
79 sed 's/^/github_api_token=/' >> $config
80}
81
82while ! source $config || [[ -z "$user" ]]; do
83 _auth
84done
85
63github_api=https://api.github.com 86github_api=https://api.github.com
64auth_header="Authorization: token $github_api_token" 87auth_header="Authorization: token $github_api_token"
65mkdir -p $folder 88mkdir -p $folder
@@ -254,20 +277,6 @@ _help_message() {
254 sed -E -n ' /^$/ q; 8,$ s/^#//p' $0 277 sed -E -n ' /^$/ q; 8,$ s/^#//p' $0
255} 278}
256 279
257_auth() {
258 data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}"
259 read -p "Github username: " user
260 read -sp "Github password: " password
261 curl https://api.github.com/authorizations \
262 --user "$user:$password" \
263 --data "$data"
264
265 read -sp "2-factor code: " OTP
266 curl https://api.github.com/authorizations \
267 --user "$user:$password" -H "X-GitHub-OTP: $OTP" \
268 --data "$data"
269}
270
271case "$1" in 280case "$1" in
272 "") 281 "")
273 _show_list $index ;; 282 _show_list $index ;;