diff options
Diffstat (limited to 'scripts/gist')
| -rwxr-xr-x | scripts/gist | 37 |
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 |
| 135 | INDEX=$folder/index | 135 | INDEX=$folder/index |
| 136 | # TODO join star file into index | ||
| 136 | STARRED=$folder/starred | 137 | STARRED=$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 | ||
| 209 | AccessJsonElement() { | 193 | AccessJsonElement() { |
| 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" |