diff options
| -rwxr-xr-x | scripts/gist | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/scripts/gist b/scripts/gist index 69de7f8..0336b5f 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -59,6 +59,7 @@ config=~/.config/gistrc | |||
| 59 | [ "$TRACE" ] && set -x | 59 | [ "$TRACE" ] && set -x |
| 60 | 60 | ||
| 61 | # TODO error handling while password is not true | 61 | # TODO error handling while password is not true |
| 62 | # TODO support access token from input or web | ||
| 62 | _auth() { | 63 | _auth() { |
| 63 | local data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}" | 64 | local data="{\"scopes\":[\"gist\"], \"note\": \"gist-$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"}" |
| 64 | read -p "Github username: " user | 65 | read -p "Github username: " user |
| @@ -77,9 +78,13 @@ _auth() { | |||
| 77 | | sed 's/^/token=/' >> $config | 78 | | sed 's/^/token=/' >> $config |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | while ! source $config || [[ -z "$token" ]] || [[ -z "$user" ]]; do | 81 | case "$1" in |
| 81 | _auth | 82 | config | c) ;; |
| 82 | done | 83 | *) |
| 84 | while ! source $config 2> /dev/null || [[ -z "$token" ]] || [[ -z "$user" ]]; do | ||
| 85 | _auth | ||
| 86 | done;; | ||
| 87 | esac | ||
| 83 | 88 | ||
| 84 | github_api=https://api.github.com | 89 | github_api=https://api.github.com |
| 85 | auth_header="Authorization: token $token" | 90 | auth_header="Authorization: token $token" |
| @@ -205,10 +210,10 @@ _clean_repos() { | |||
| 205 | # TODO format with simple text | 210 | # TODO format with simple text |
| 206 | _show_detail() { | 211 | _show_detail() { |
| 207 | _gist_id $1 | 212 | _gist_id $1 |
| 208 | curl -s -H "$auth_header" $github_api/gists/$GIST_ID \ | 213 | curl -s $github_api/gists/$GIST_ID \ |
| 209 | | jq '{site: .html_url, description: .description, public: .public, API: .url, created_at: .created_at, updated_at: .updated_at, files: (.files | keys)}' | 214 | | jq '{site: .html_url, description: .description, public: .public, API: .url, created_at: .created_at, updated_at: .updated_at, files: (.files | keys)}' |
| 210 | 215 | ||
| 211 | curl -s -H "$auth_header" $github_api/gists/$GIST_ID/comments \ | 216 | curl -s $github_api/gists/$GIST_ID/comments \ |
| 212 | | jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' | 217 | | jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' |
| 213 | } | 218 | } |
| 214 | 219 | ||