diff options
Diffstat (limited to 'scripts/gist')
| -rwxr-xr-x | scripts/gist | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist index fe38e38..a939a47 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -56,7 +56,6 @@ | |||
| 56 | # TODO completion | 56 | # TODO completion |
| 57 | 57 | ||
| 58 | # Shell configuration | 58 | # Shell configuration |
| 59 | set -eo pipefail | ||
| 60 | [ "$TRACE" ] && set -x | 59 | [ "$TRACE" ] && set -x |
| 61 | 60 | ||
| 62 | GITHUB_API=https://api.github.com | 61 | GITHUB_API=https://api.github.com |
| @@ -203,7 +202,7 @@ _show_list() { | |||
| 203 | # parse JSON from STDIN with string of commands | 202 | # parse JSON from STDIN with string of commands |
| 204 | AccessJsonElement() { | 203 | AccessJsonElement() { |
| 205 | PYTHONIOENCODING=utf-8 \ | 204 | PYTHONIOENCODING=utf-8 \ |
| 206 | python -c "from __future__ import print_function; import sys, json; raw = json.load(sys.stdin); $1" | 205 | python -c "from __future__ import print_function; import sys, json; raw = json.load(sys.stdin); $1" 2> /dev/null |
| 207 | return "$?" | 206 | return "$?" |
| 208 | } | 207 | } |
| 209 | 208 | ||
| @@ -247,7 +246,7 @@ _update() { | |||
| 247 | fi | 246 | fi |
| 248 | 247 | ||
| 249 | response=$(curl -H "$auth_header" $GITHUB_API/$route) | 248 | response=$(curl -H "$auth_header" $GITHUB_API/$route) |
| 250 | false && echo Fail to update gists && return 1 | 249 | false && echo Failed to update gists && return 1 |
| 251 | sed -i "$filter" $INDEX | 250 | sed -i "$filter" $INDEX |
| 252 | echo $response | _parse_response >> $INDEX | 251 | echo $response | _parse_response >> $INDEX |
| 253 | _show_list $mark | 252 | _show_list $mark |
| @@ -393,12 +392,12 @@ _new_file() { | |||
| 393 | } | 392 | } |
| 394 | 393 | ||
| 395 | # create a new gist with files | 394 | # create a new gist with files |
| 396 | # FIXME catch status code from curl if it fails | ||
| 397 | _create_gist() { | 395 | _create_gist() { |
| 398 | _set_gist "$@" || return 1 | 396 | _set_gist "$@" || return 1 |
| 399 | [[ -z "$files" ]] && files=$(_new_file $filename) | 397 | [[ -z "$files" ]] && files=$(_new_file $filename) |
| 400 | [[ -z "$description" ]] && read -p 'Type description: ' description < /dev/tty | 398 | [[ -z "$description" ]] && read -p 'Type description: ' description < /dev/tty |
| 401 | 399 | ||
| 400 | index=$(( $(sed '/^s/ d' $INDEX | wc -l) +1 )) | ||
| 402 | echo 'Creating a new gist' | 401 | echo 'Creating a new gist' |
| 403 | for file in $files; do | 402 | for file in $files; do |
| 404 | echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"}," | 403 | echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"}," |
| @@ -406,11 +405,14 @@ _create_gist() { | |||
| 406 | | echo "{ \"public\": $public, \"files\": $(cat -), \"description\": \"$description\"}" \ | 405 | | echo "{ \"public\": $public, \"files\": $(cat -), \"description\": \"$description\"}" \ |
| 407 | | curl -s -H "$auth_header" --data @- $GITHUB_API/gists \ | 406 | | curl -s -H "$auth_header" --data @- $GITHUB_API/gists \ |
| 408 | | sed '1 s/^/[/; $ s/$/]/' \ | 407 | | sed '1 s/^/[/; $ s/$/]/' \ |
| 409 | | _parse_response $(( $(sed '/^s/ d' $INDEX | wc -l) +1 )) >> $INDEX \ | 408 | | _parse_response $index >> $INDEX |
| 410 | && echo -e '\nGist created' \ | ||
| 411 | || echo 'Fail to create gist' | ||
| 412 | 409 | ||
| 413 | _show_list | tail -1 | 410 | if [[ "$?" -ne 0 ]]; then |
| 411 | echo 'Gist is created' | ||
| 412 | _show_list | tail -1 | ||
| 413 | else | ||
| 414 | echo 'Failed to create gist' | ||
| 415 | fi | ||
| 414 | } | 416 | } |
| 415 | 417 | ||
| 416 | # update description of a gist | 418 | # update description of a gist |