summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-01-31 13:07:30 +0800
committertypebrook <typebrook@gmail.com>2020-01-31 13:07:30 +0800
commit83568dc7b96f3747895084d006d6030a5c9414c6 (patch)
treeb9f619d7328cb8dae25fa82916677e72c610425b /scripts/gist
parentde1a89440b2d583435a212d98cb301f0b24efe9b (diff)
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist37
1 files changed, 19 insertions, 18 deletions
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"
133 133
134[[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder 134[[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder
135INDEX=$folder/index 135INDEX=$folder/index
136# TODO join star file into index
136STARRED=$folder/starred 137STARRED=$folder/starred
137 138
138## This function determines which http get tool the system has installed and returns an error if there isnt one 139## 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() {
188 done 189 done
189} 190}
190 191
191# get the list of gists 192# parse JSON from STDIN with string of commands
192_update() {
193 echo "fetching $user's gists from $GITHUB_API..."
194 echo
195 local list_file=$INDEX
196 local route="users/$user/gists"
197 local mark=""
198 [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred" && mark="s"
199
200 httpGet $GITHUB_API/$route \
201 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \
202 && _show_list $list_file \
203 || echo Fail to update gists
204
205 if [[ $auto_sync != "false" ]]; then (_sync_repos $1 > /dev/null 2>&1 &); fi
206}
207
208## parse JSON from STDIN with string of commands
209AccessJsonElement() { 193AccessJsonElement() {
210 PYTHONIOENCODING=utf-8 \ 194 PYTHONIOENCODING=utf-8 \
211 python -c "from __future__ import print_function; import sys, json; raw = json.load(sys.stdin); $1" 195 python -c "from __future__ import print_function; import sys, json; raw = json.load(sys.stdin); $1"
@@ -234,6 +218,23 @@ _parse_response() {
234 done 218 done
235} 219}
236 220
221# get the list of gists
222_update() {
223 echo "fetching $user's gists from $GITHUB_API..."
224 echo
225 local list_file=$INDEX
226 local route="users/$user/gists"
227 local mark=""
228 [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred" && mark="s"
229
230 httpGet $GITHUB_API/$route \
231 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \
232 && _show_list $list_file \
233 || echo Fail to update gists
234
235 if [[ $auto_sync != "false" ]]; then (_sync_repos $1 > /dev/null 2>&1 &); fi
236}
237
237_sync_repos() { 238_sync_repos() {
238 local list_file=$INDEX 239 local list_file=$INDEX
239 [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred" 240 [[ "$1" =~ ^(star|s)$ ]] && list_file=$STARRED && route="gists/starred"