diff options
author | typebrook <typebrook@gmail.com> | 2020-01-29 11:04:24 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-01-29 11:04:24 +0800 |
commit | af2ff2e4ef1403fb2d8a6ce493589d9171c35a4a (patch) | |
tree | 2df6a3e2d651f5df9db90ce7e29b2840a408aa1a | |
parent | 7bf9eb1c113261a10dcd9e0cc0ea07822516ee30 (diff) |
update
-rwxr-xr-x | scripts/gist | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/scripts/gist b/scripts/gist index 19ab6a6..7da458d 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -46,7 +46,7 @@ | |||
46 | # It is your business to do git commit and git push | 46 | # It is your business to do git commit and git push |
47 | # | 47 | # |
48 | # * configuration | 48 | # * configuration |
49 | # gist (config | c) [token <value>] [user <value>] [folder <value>] | 49 | # gist (config | c) [token <value>] [user <value>] [folder <value>] [auto-sync false] |
50 | # | 50 | # |
51 | # * show this help message | 51 | # * show this help message |
52 | # gist (help | h) | 52 | # gist (help | h) |
@@ -61,7 +61,7 @@ config=~/.config/gistrc | |||
61 | set -eo pipefail | 61 | set -eo pipefail |
62 | [ "$TRACE" ] && set -x | 62 | [ "$TRACE" ] && set -x |
63 | 63 | ||
64 | ## Grabs an element from a a json string and then echoes it to stdout | 64 | ## parse JSON from STDIN with string of commands |
65 | AccessJsonElement() { | 65 | AccessJsonElement() { |
66 | PYTHONIOENCODING=utf-8 python -c "from __future__ import print_function; import sys, json; raw = json.load(sys.stdin); $1" | 66 | PYTHONIOENCODING=utf-8 python -c "from __future__ import print_function; import sys, json; raw = json.load(sys.stdin); $1" |
67 | return "$?" | 67 | return "$?" |
@@ -152,7 +152,7 @@ _update() { | |||
152 | } | 152 | } |
153 | 153 | ||
154 | # equal to: jq '.[] | "\(.html_url) \([.files[] | .raw_url]) \(.files | keys | length) \(.comments) \(.description)"' | 154 | # equal to: jq '.[] | "\(.html_url) \([.files[] | .raw_url]) \(.files | keys | length) \(.comments) \(.description)"' |
155 | handle_gists() { | 155 | _handle_gists() { |
156 | echo ' | 156 | echo ' |
157 | for gist in raw: | 157 | for gist in raw: |
158 | print(gist["html_url"], end=" ") | 158 | print(gist["html_url"], end=" ") |
@@ -165,7 +165,7 @@ for gist in raw: | |||
165 | 165 | ||
166 | # TODO check if a user create a very first gist | 166 | # TODO check if a user create a very first gist |
167 | _parse_response() { | 167 | _parse_response() { |
168 | AccessJsonElement "$(handle_gists)" \ | 168 | AccessJsonElement "$(_handle_gists)" \ |
169 | | tac | sed 's/, /,/g'\ | 169 | | tac | sed 's/, /,/g'\ |
170 | | while read link file_url_array file_num comment_num description; do | 170 | | while read link file_url_array file_num comment_num description; do |
171 | local blob_code=$(echo $file_url_array | tr ',' '\n' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') | 171 | local blob_code=$(echo $file_url_array | tr ',' '\n' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') |
@@ -241,11 +241,25 @@ _clean_repos() { | |||
241 | done | 241 | done |
242 | } | 242 | } |
243 | 243 | ||
244 | _handle_gist() { | ||
245 | echo ' | ||
246 | print("site:", raw["html_url"]) | ||
247 | print("description:", raw["description"]) | ||
248 | print("public:", raw["public"]) | ||
249 | print("API:", raw["url"]) | ||
250 | print("created_at:", raw["created_at"]) | ||
251 | print("updated_at:", raw["updated_at"]) | ||
252 | print("files:") | ||
253 | for file in raw["files"].keys(): | ||
254 | print(" ", file) | ||
255 | ' | ||
256 | } | ||
257 | |||
244 | # TODO format with simple text | 258 | # TODO format with simple text |
245 | _show_detail() { | 259 | _show_detail() { |
246 | _gist_id $1 | 260 | _gist_id $1 |
247 | curl -s $github_api/gists/$GIST_ID \ | 261 | curl -s $github_api/gists/$GIST_ID \ |
248 | | jq '{site: .html_url, description: .description, public: .public, API: .url, created_at: .created_at, updated_at: .updated_at, files: (.files | keys)}' | 262 | | AccessJsonElement "$(_handle_gist)" |
249 | 263 | ||
250 | curl -s $github_api/gists/$GIST_ID/comments \ | 264 | curl -s $github_api/gists/$GIST_ID/comments \ |
251 | | jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' | 265 | | jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' |