summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist16
1 files changed, 8 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist
index 57ef6ec..34d1351 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -62,7 +62,7 @@
62set -eo pipefail 62set -eo pipefail
63[ "$TRACE" ] && set -x 63[ "$TRACE" ] && set -x
64 64
65github_api=https://api.github.com 65GITHUB_API=https://api.github.com
66config=~/.config/gistrc 66config=~/.config/gistrc
67mkdir -p ~/.config && umask 0077 67mkdir -p ~/.config && umask 0077
68 68
@@ -161,14 +161,14 @@ _show_list() {
161 161
162# get the list of gists 162# get the list of gists
163_update() { 163_update() {
164 echo "fetching from api.github.com..." 164 echo "fetching $user's gists from $GITHUB_API..."
165 echo 165 echo
166 local list_file=$index 166 local list_file=$index
167 local route="users/$user/gists" 167 local route="users/$user/gists"
168 local mark="" 168 local mark=""
169 [[ "$1" =~ ^(star|s)$ ]] && list_file=$starred && route="gists/starred" && mark="s" 169 [[ "$1" =~ ^(star|s)$ ]] && list_file=$starred && route="gists/starred" && mark="s"
170 170
171 curl -s $github_api/$route \ 171 curl -s $GITHUB_API/$route \
172 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \ 172 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \
173 && _show_list $list_file \ 173 && _show_list $list_file \
174 || echo Fail to update gists 174 || echo Fail to update gists
@@ -260,7 +260,7 @@ _goto_gist() {
260_delete_gist() { 260_delete_gist() {
261 for i in "$@"; do 261 for i in "$@"; do
262 _gist_id "$i" 262 _gist_id "$i"
263 curl -X DELETE -s -H "$auth_header" $github_api/gists/$GIST_ID \ 263 curl -X DELETE -s -H "$auth_header" $GITHUB_API/gists/$GIST_ID \
264 && echo "$i" deleted \ 264 && echo "$i" deleted \
265 && sed -i -E "/^$i / d" $index 265 && sed -i -E "/^$i / d" $index
266 done 266 done
@@ -304,10 +304,10 @@ for comment in raw:
304# TODO format with simple text 304# TODO format with simple text
305_show_detail() { 305_show_detail() {
306 _gist_id $1 306 _gist_id $1
307 curl -s $github_api/gists/$GIST_ID \ 307 curl -s $GITHUB_API/gists/$GIST_ID \
308 | AccessJsonElement "$(_handle_gist)" 308 | AccessJsonElement "$(_handle_gist)"
309 309
310 curl -s $github_api/gists/$GIST_ID/comments \ 310 curl -s $GITHUB_API/gists/$GIST_ID/comments \
311 | AccessJsonElement "$(_handle_comment)" 311 | AccessJsonElement "$(_handle_comment)"
312} 312}
313 313
@@ -349,7 +349,7 @@ _create_gist() {
349 echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"}," 349 echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"},"
350 done | tr -d '\n' | sed 's/^/{/; s/,$/}/' \ 350 done | tr -d '\n' | sed 's/^/{/; s/,$/}/' \
351 | echo "{ \"public\": true, \"files\": $(cat -), \"description\": \"$description\"}" \ 351 | echo "{ \"public\": true, \"files\": $(cat -), \"description\": \"$description\"}" \
352 | curl -s -H "$auth_header" --data @- $github_api/gists \ 352 | curl -s -H "$auth_header" --data @- $GITHUB_API/gists \
353 | sed '1 s/^/[/; $ s/$/]/' \ 353 | sed '1 s/^/[/; $ s/$/]/' \
354 | _parse_response \ 354 | _parse_response \
355 | sed -E "s/^/$(( $(wc -l $index | cut -d' ' -f1) + 1 )) /" >> $index \ 355 | sed -E "s/^/$(( $(wc -l $index | cut -d' ' -f1) + 1 )) /" >> $index \
@@ -366,7 +366,7 @@ _edit_gist() {
366 echo -n 'Type new description: ' 366 echo -n 'Type new description: '
367 read DESC < /dev/tty 367 read DESC < /dev/tty
368 echo "{ \"description\": \"$DESC\" }" \ 368 echo "{ \"description\": \"$DESC\" }" \
369 | curl -X PATCH -H "$auth_header" --data @- $github_api/gists/$GIST_ID > /dev/null \ 369 | curl -X PATCH -H "$auth_header" --data @- $GITHUB_API/gists/$GIST_ID > /dev/null \
370 && _update 370 && _update
371} 371}
372 372