summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xscripts/gist23
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
81while ! source $config 2> /dev/tty || [[ -z "$user" ]] || [[ -z "$github_api_token" ]]; do 80while ! source $config &> /dev/null || [[ -z "$user" ]] || [[ -z "$github_api_token" ]]; do
82 _auth 81 _auth
83done 82done
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
279case "$1" in 287case "$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 *)