diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/gist | 41 |
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 | #------------------- |
58 | github_api_token=$(cat $SETTING_DIR/tokens/gist) | ||
59 | user=typebrook | ||
60 | folder=~/git/gist | 58 | folder=~/git/gist |
59 | config=~/.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 | |||
82 | while ! source $config || [[ -z "$user" ]]; do | ||
83 | _auth | ||
84 | done | ||
85 | |||
63 | github_api=https://api.github.com | 86 | github_api=https://api.github.com |
64 | auth_header="Authorization: token $github_api_token" | 87 | auth_header="Authorization: token $github_api_token" |
65 | mkdir -p $folder | 88 | mkdir -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 | |||
271 | case "$1" in | 280 | case "$1" in |
272 | "") | 281 | "") |
273 | _show_list $index ;; | 282 | _show_list $index ;; |