summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist24
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
61set -eo pipefail 61set -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
65AccessJsonElement() { 65AccessJsonElement() {
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)"'
155handle_gists() { 155_handle_gists() {
156 echo ' 156 echo '
157for gist in raw: 157for 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 '
246print("site:", raw["html_url"])
247print("description:", raw["description"])
248print("public:", raw["public"])
249print("API:", raw["url"])
250print("created_at:", raw["created_at"])
251print("updated_at:", raw["updated_at"])
252print("files:")
253for 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}'