aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-03-14 23:05:08 +0800
committertypebrook <typebrook@gmail.com>2020-03-14 23:05:08 +0800
commit04bc794c495ea9158c86c624b2a4118442ff6abe (patch)
treec385aec7d41574b630d80041f7768c965da73b8f
parentbce8cc6b95b639b0c59f61449fd1aba6b0f8c5ae (diff)
Refactor behavior about subcommand 'detail'
- Store created/updated time inside index file - gist detail only shows the content from index file
-rwxr-xr-xgist39
1 files changed, 15 insertions, 24 deletions
diff --git a/gist b/gist
index 78dedcf..74a0f85 100755
--- a/gist
+++ b/gist
@@ -259,7 +259,7 @@ _show_list() {
259 259
260 local prefix=$mark; [[ -z $prefix ]] && prefix=[^s] 260 local prefix=$mark; [[ -z $prefix ]] && prefix=[^s]
261 sed -Ene "/^$prefix/ p" $INDEX \ 261 sed -Ene "/^$prefix/ p" $INDEX \
262 | while read -r index link blob_code file_num comment_num author description; do 262 | while read -r index link blob_code file_num comment_num author _ _ description; do
263 [[ $index =~ ^s ]] && local name=$author 263 [[ $index =~ ^s ]] && local name=$author
264 local repo; repo=$folder/${link##*/} 264 local repo; repo=$folder/${link##*/}
265 local extra; extra=$(_check_repo_status "$repo" "$blob_code") 265 local extra; extra=$(_check_repo_status "$repo" "$blob_code")
@@ -303,6 +303,8 @@ for gist in raw:
303 print(len(gist["files"]), end=" ") 303 print(len(gist["files"]), end=" ")
304 print(gist["comments"], end=" ") 304 print(gist["comments"], end=" ")
305 print(gist["owner"]["login"], end=" ") 305 print(gist["owner"]["login"], end=" ")
306 print(gist["created_at"], end=" ")
307 print(gist["updated_at"], end=" ")
306 print(gist["description"]) 308 print(gist["description"])
307 ' 309 '
308} 310}
@@ -311,11 +313,11 @@ for gist in raw:
311_parse_response() { 313_parse_response() {
312 _parse_gists \ 314 _parse_gists \
313 | tac | sed -e 's/, /,/g' | nl -s' ' \ 315 | tac | sed -e 's/, /,/g' | nl -s' ' \
314 | while read -r index link file_url_array public file_num comment_num author description; do 316 | while read -r index link file_url_array public file_num comment_num author created_at updated_at description; do
315 local blob_code; blob_code=$(echo "$file_url_array" | tr ',' '\n' | sed -E -e 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -s -d '-' -) 317 local blob_code; blob_code=$(echo "$file_url_array" | tr ',' '\n' | sed -E -e 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -s -d '-' -)
316 local prefix=$mark; [[ $public == 'False' ]] && prefix=p 318 local prefix=$mark; [[ $public == 'False' ]] && prefix=p
317 [[ -n $1 ]] && local index=$1 319 [[ -n $1 ]] && local index=$1
318 echo "$prefix$index $link $blob_code $file_num $comment_num $author $description" | tr -d '"' 320 echo "$prefix$index $link $blob_code $file_num $comment_num $author $created_at $updated_at $description" | tr -d '"'
319 done 321 done
320} 322}
321 323
@@ -448,22 +450,6 @@ _clean_repos() {
448 done 450 done
449} 451}
450 452
451# parse JSON from gist detail
452_parse_gist() {
453 _process_json '
454raw = json.load(sys.stdin)
455print("site:", raw["html_url"])
456print("description:", raw["description"])
457print("public:", raw["public"])
458print("API:", raw["url"])
459print("created_at:", raw["created_at"])
460print("updated_at:", raw["updated_at"])
461print("files:")
462for file in raw["files"].keys():
463 print(" ", file)
464 '
465}
466
467# equal to jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}' 453# equal to jq '.[] | {user: .user.login, created_at: .created_at, updated_at: .updated_at, body: .body}'
468_parse_comment() { 454_parse_comment() {
469 _process_json ' 455 _process_json '
@@ -479,11 +465,16 @@ for comment in raw:
479 465
480_show_detail() { 466_show_detail() {
481 _gist_id "$1" || return 1 467 _gist_id "$1" || return 1
482 http_method GET "$GITHUB_API/gists/$GIST_ID" \ 468 record=$(sed -ne "/^$1 / p" $INDEX)
483 | _parse_gist 469 echo description: $(echo $record | cut -d' ' -f9-)
484 470 echo site: https://gist.github.com/$GIST_ID
485 http_method GET "$GITHUB_API/gists/$GIST_ID"/comments \ 471 echo API: https://api.github.com/gists/$GIST_ID
486 | _parse_comment 472 echo created_at: $(echo $record | cut -d' ' -f7)
473 echo updated_at: $(echo $record | cut -d' ' -f8)
474 if [[ -d $folder/$GIST_ID ]]; then
475 echo files
476 ls | sed -e 's/^/ /'
477 fi
487} 478}
488 479
489# set filename/description/permission for a new gist 480# set filename/description/permission for a new gist