diff options
author | typebrook <typebrook@gmail.com> | 2020-01-21 18:23:27 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-01-21 18:23:27 +0800 |
commit | 8234fceb4be491ebba05de35f6d8456fb64c4015 (patch) | |
tree | 82f5ea8281e0a8221c8361aac57dbc9f0b7ffa52 | |
parent | 87d397b0a88b78ca7258d1326b12e529faa12d37 (diff) |
update
-rwxr-xr-x | scripts/gist | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/scripts/gist b/scripts/gist index a01f2ba..876371e 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -63,22 +63,21 @@ _auth() { | |||
63 | data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}" | 63 | data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}" |
64 | read -p "Github username: " user | 64 | read -p "Github username: " user |
65 | read -sp "Github password: " password | 65 | read -sp "Github password: " password |
66 | mkdir -p ~/.config | 66 | mkdir -p ~/.config && umask 0077 && echo user=$user > $config |
67 | umask 0077 && echo user=$user > $config | ||
68 | 67 | ||
69 | curl -s https://api.github.com/authorizations \ | 68 | curl https://api.github.com/authorizations \ |
70 | --user "$user:$password" \ | 69 | --user "$user:$password" \ |
71 | --data "$data" > /dev/null | 70 | --data "$data" > /dev/null |
72 | 71 | ||
73 | read -p "2-factor code: " OTP | 72 | read -p "2-factor code: " OTP |
74 | curl -s https://api.github.com/authorizations \ | 73 | curl https://api.github.com/authorizations \ |
75 | --user "$user:$password" -H "X-GitHub-OTP: $OTP" \ | 74 | --user "$user:$password" -H "X-GitHub-OTP: $OTP" \ |
76 | --data "$data" |\ | 75 | --data "$data" |\ |
77 | sed '1 s/[^{]//g' | jq -r .token |\ | 76 | sed '1 s/[^{]//g' | jq -r .token |\ |
78 | sed 's/^/github_api_token=/' >> $config | 77 | sed 's/^/github_api_token=/' >> $config |
79 | } | 78 | } |
80 | 79 | ||
81 | while ! source $config 2> /dev/tty || [[ -z "$user" ]] || [[ -z "$github_api_token" ]]; do | 80 | while ! source $config &> /dev/null || [[ -z "$user" ]] || [[ -z "$github_api_token" ]]; do |
82 | _auth | 81 | _auth |
83 | done | 82 | done |
84 | 83 | ||
@@ -128,7 +127,7 @@ _update() { | |||
128 | curl -s -H "$auth_header" $github_api/$route |\ | 127 | curl -s -H "$auth_header" $github_api/$route |\ |
129 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file && \ | 128 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file && \ |
130 | _show_list $list_file | 129 | _show_list $list_file |
131 | [[ $auto_sync ]] && (_sync_repos $1 > /dev/null 2>&1 &) | 130 | if [[ $auto_sync != "false" ]]; then (_sync_repos $1 > /dev/null 2>&1 &); fi |
132 | } | 131 | } |
133 | 132 | ||
134 | # TODO check if a user create a very first gist | 133 | # TODO check if a user create a very first gist |
@@ -276,6 +275,15 @@ _help_message() { | |||
276 | sed -E -n ' /^$/ q; 8,$ s/^#//p' $0 | 275 | sed -E -n ' /^$/ q; 8,$ s/^#//p' $0 |
277 | } | 276 | } |
278 | 277 | ||
278 | _configure() { | ||
279 | case $i in | ||
280 | auto_sync) | ||
281 | ;; | ||
282 | folder) | ||
283 | ;; | ||
284 | esac | ||
285 | } | ||
286 | |||
279 | case "$1" in | 287 | case "$1" in |
280 | "") | 288 | "") |
281 | _show_list $index ;; | 289 | _show_list $index ;; |
@@ -298,6 +306,9 @@ case "$1" in | |||
298 | _delete_gist "$@" ;; | 306 | _delete_gist "$@" ;; |
299 | clean | C) | 307 | clean | C) |
300 | _clean_repos ;; | 308 | _clean_repos ;; |
309 | config | c) | ||
310 | shift | ||
311 | _configure "$@" ;; | ||
301 | help | h) | 312 | help | h) |
302 | _help_message ;; | 313 | _help_message ;; |
303 | *) | 314 | *) |