From 83568dc7b96f3747895084d006d6030a5c9414c6 Mon Sep 17 00:00:00 2001 From: typebrook Date: Fri, 31 Jan 2020 13:07:30 +0800 Subject: update --- scripts/gist | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'scripts/gist') diff --git a/scripts/gist b/scripts/gist index 8e5e36c..f33f83f 100755 --- a/scripts/gist +++ b/scripts/gist @@ -133,6 +133,7 @@ auth_header="Authorization: token $token" [[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder INDEX=$folder/index +# TODO join star file into index STARRED=$folder/starred ## This function determines which http get tool the system has installed and returns an error if there isnt one @@ -188,24 +189,7 @@ _show_list() { done } -# get the list of gists -_update() { - echo "fetching $user's gists from $GITHUB_API..." - echo - local list_file=$INDEX - local route="users/$user/gists" - local mark="" - [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred" && mark="s" - - httpGet $GITHUB_API/$route \ - | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \ - && _show_list $list_file \ - || echo Fail to update gists - - if [[ $auto_sync != "false" ]]; then (_sync_repos $1 > /dev/null 2>&1 &); fi -} - -## parse JSON from STDIN with string of commands +# parse JSON from STDIN with string of commands AccessJsonElement() { PYTHONIOENCODING=utf-8 \ python -c "from __future__ import print_function; import sys, json; raw = json.load(sys.stdin); $1" @@ -234,6 +218,23 @@ _parse_response() { done } +# get the list of gists +_update() { + echo "fetching $user's gists from $GITHUB_API..." + echo + local list_file=$INDEX + local route="users/$user/gists" + local mark="" + [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred" && mark="s" + + httpGet $GITHUB_API/$route \ + | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \ + && _show_list $list_file \ + || echo Fail to update gists + + if [[ $auto_sync != "false" ]]; then (_sync_repos $1 > /dev/null 2>&1 &); fi +} + _sync_repos() { local list_file=$INDEX [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred" -- cgit v1.2.3-70-g09d2