diff options
-rwxr-xr-x | gist | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -436,6 +436,13 @@ _fetch_gists_with_pagnation() { | |||
436 | #result=$(printf "${extra:+$extra\n}$result") | 436 | #result=$(printf "${extra:+$extra\n}$result") |
437 | } | 437 | } |
438 | 438 | ||
439 | # Get a single JSON object of gist from response, and update index file | ||
440 | _update_gist() { | ||
441 | local index=$1 | ||
442 | local record=$(sed -e '1 s/^/[/; $ s/$/]/' | start_from_num="${index#[[:alpha:]]}" _parse_response) | ||
443 | [[ -n $record ]] && sed -i'' -Ee "/^$index / s^.+^$record^" $INDEX | ||
444 | } | ||
445 | |||
439 | # Fetch gists for a given user | 446 | # Fetch gists for a given user |
440 | # TODO pagnation for more than 100 gists | 447 | # TODO pagnation for more than 100 gists |
441 | _query_user() { | 448 | _query_user() { |
@@ -621,8 +628,8 @@ _push_to_remote() { | |||
621 | git add . && git commit -m 'update' | 628 | git add . && git commit -m 'update' |
622 | fi | 629 | fi |
623 | if [[ -n $(git cherry) ]]; then | 630 | if [[ -n $(git cherry) ]]; then |
624 | # FIXME only fetch one gist | 631 | git push origin master && \ |
625 | git push origin master && (hint=false _fetch_gists_with_pagnation &> /dev/null &) | 632 | (http_method GET "$GITHUB_API/gists/$GIST_ID" | _update_gist $1 &> /dev/null &) |
626 | fi | 633 | fi |
627 | } | 634 | } |
628 | 635 | ||
@@ -720,10 +727,8 @@ _edit_gist() { | |||
720 | 727 | ||
721 | http_data=$(tmp_file PAYLOAD.EDIT) | 728 | http_data=$(tmp_file PAYLOAD.EDIT) |
722 | echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" | 729 | echo '{' \"description\": \""${DESC//\"/\\\"}"\" '}' > "$http_data" |
723 | new_record=$(http_method PATCH "$GITHUB_API/gists/$GIST_ID" \ | 730 | |
724 | | sed -e '1 s/^/[/; $ s/$/]/' \ | 731 | http_method PATCH "$GITHUB_API/gists/$GIST_ID" | _update_gist $index \ |
725 | | start_from_index="${index#[[:alpha:]]}" _parse_response) | ||
726 | [[ -n $new_record ]] && sed -i'' -E -e "/^$index / s^.+^$new_record^" $INDEX \ | ||
727 | && hint=false mark="$index " _show_list \ | 732 | && hint=false mark="$index " _show_list \ |
728 | || echo 'Fail to modify gist description' | 733 | || echo 'Fail to modify gist description' |
729 | } | 734 | } |