From e767195f290b2b5b60d6a4fb9fa26fb9698cbfe8 Mon Sep 17 00:00:00 2001 From: typebrook Date: Thu, 6 Feb 2020 08:35:56 +0800 Subject: update --- scripts/gist | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/gist b/scripts/gist index b901046..a40a6a1 100755 --- a/scripts/gist +++ b/scripts/gist @@ -30,7 +30,6 @@ # Since now a gist is a local cloned repo # It is your business to do git commit and git push -# TODO push github.com (may need new token) # TODO test on bats, mac and remote machine # TODO completion @@ -165,7 +164,7 @@ _show_list() { [[ -z $1 ]] && local filter='/^ *s/ d; /^$/ d' [[ $1 == "s" ]] && local filter='/^ *[^ s]/ d; /^$/ d' - while read index link blob_code file_num extra author description; do + while read index link files blob_code file_num extra author description; do [[ $1 == "s" ]] && local name=$author local repo=$folder/$(echo $link | sed 's#.*/##') local occupy=0 @@ -201,7 +200,8 @@ _handle_gists() { raw = json.load(sys.stdin) for gist in raw: print(gist["html_url"], end=" ") - print([file["raw_url"] for file in gist["files"].values()], end=" ") + print([file for file in gist["files"].keys()], end=" ") + print([details["raw_url"] for details in gist["files"].values()], end=" ") print(gist["public"], end=" ") print(len(gist["files"]), end=" ") print(gist["comments"], end=" ") @@ -212,14 +212,15 @@ for gist in raw: # TODO check if a user create a very first gist # parse response from gists require -_parse_response() { +_parse_gists() { AccessJsonElement "$(_handle_gists)" \ | tac | sed 's/, /,/g' | nl -s' ' \ - | while read index link file_url_array public file_num comment_num author description; do + | while read index link file_array file_url_array public file_num comment_num author description; do + local files=$(echo $file_array | sed -E "s/.*'(.+)'.*/\1/g" | tr ',' '-') local blob_code=$(echo $file_url_array | tr ',' '\n' | sed -E 's#.*raw/(.*)/.*#\1#' | sort | cut -c -7 | paste -sd '-') [[ $public == 'False' ]] && local mark=p [[ -n $1 ]] && local index=$1 - echo $mark$index $link $blob_code $file_num $comment_num $author $description | tr -d '"' + echo $mark$index $link $files $blob_code $file_num $comment_num $author $description | tr -d '"' done } @@ -237,7 +238,7 @@ _update() { filter='/^[s]/ d; /^$/ d' fi - result=$(http_method GET $GITHUB_API/$route | _parse_response) + result=$(http_method GET $GITHUB_API/$route | _parse_gists) [[ -z $result ]] && echo Failed to update gists && return 1 sed -i "$filter" $INDEX && echo "$result" >> $INDEX @@ -248,11 +249,11 @@ _update() { _query_user() { local route="users/$1/gists" - result=$(http_method GET $GITHUB_API/$route | _parse_response) + result=$(http_method GET $GITHUB_API/$route | _parse_gists) [[ -z $result ]] && echo Failed to update gists && return 1 echo "$result" \ - | while read index link blob_code file_num extra description; do + | while read index link files blob_code file_num extra description; do echo $link $file_num $extra $(echo $description | cut -c -70 ) done } @@ -265,7 +266,7 @@ _sync_repos() { | xargs -I{} --max-procs 8 git clone git@github.com:{}.git $folder/{} # pull if remote repo has different blob objects - cat $INDEX | cut -d' ' -f2,3 \ + cat $INDEX | cut -d' ' -f2,4 \ | while read url blob_code_remote; do local repo=$folder/$(echo $url | sed 's#.*/##') local blob_code_local=$(cd $repo && git ls-tree master | cut -d' ' -f3 | cut -c-7 | sort | paste -sd '-') @@ -423,7 +424,7 @@ _create_gist() { | AccessJsonElement "$(_gist_body)" > $http_data \ && http_method POST $GITHUB_API/gists \ | sed '1 s/^/[/; $ s/$/]/' \ - | _parse_response $(( $(sed '/^s/ d' $INDEX | wc -l) +1 )) \ + | _parse_gists $(( $(sed '/^s/ d' $INDEX | wc -l) +1 )) \ | tee -a $INDEX \ | cut -d' ' -f2 | sed -E 's#.*/##' \ | (xargs -I{} git clone git@github.com:{}.git $folder/{} &> /dev/null &) -- cgit v1.2.3-70-g09d2