summaryrefslogtreecommitdiffhomepage
path: root/scripts/gist
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-01-27 22:23:58 +0800
committertypebrook <typebrook@gmail.com>2020-01-27 22:23:58 +0800
commit84aae904698cfc5c7765071bffbe7e186a5be847 (patch)
tree5e9e5b691354b69a84b240d2a7ed0625cd040d2d /scripts/gist
parentebdb1b4a013cef757d02dc67b310dbe504014892 (diff)
update
Diffstat (limited to 'scripts/gist')
-rwxr-xr-xscripts/gist15
1 files changed, 10 insertions, 5 deletions
diff --git a/scripts/gist b/scripts/gist
index 132a185..1e65892 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -58,6 +58,7 @@
58 58
59# Validate settings. 59# Validate settings.
60config=~/.config/gistrc 60config=~/.config/gistrc
61set -eo pipefail
61[ "$TRACE" ] && set -x 62[ "$TRACE" ] && set -x
62 63
63# TODO error handling while password is not true 64# TODO error handling while password is not true
@@ -133,8 +134,10 @@ _update() {
133 [[ "$1" =~ ^(star|s)$ ]] && list_file=$starred && route="gists/starred" && mark="s" 134 [[ "$1" =~ ^(star|s)$ ]] && list_file=$starred && route="gists/starred" && mark="s"
134 135
135 curl -s -H "$auth_header" $github_api/$route \ 136 curl -s -H "$auth_header" $github_api/$route \
136 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file && \ 137 | _parse_response | nl -s' ' | sed -E "s/^ */$mark/" > $list_file \
137 _show_list $list_file 138 && show_list $list_file \
139 || echo Fail to update gists && exit 1
140
138 if [[ $auto_sync != "false" ]]; then (_sync_repos $1 > /dev/null 2>&1 &); fi 141 if [[ $auto_sync != "false" ]]; then (_sync_repos $1 > /dev/null 2>&1 &); fi
139} 142}
140 143
@@ -267,11 +270,13 @@ _create_gist() {
267 files: add, 270 files: add,
268 description: ($DESC) 271 description: ($DESC)
269 }' \ 272 }' \
270 | curl -H "$auth_header" --data @- $github_api/gists \ 273 | curl -s -H "$auth_header" --data @- $github_api/gists \
271 | sed '1 s/^/[/; $ s/$/]/' \ 274 | sed '1 s/^/[/; $ s/$/]/' \
272 | _parse_response \ 275 | _parse_response \
273 | sed -E "s/^/$(( $(wc -l $index | cut -d' ' -f1) + 1 )) /" >> $index && \ 276 | sed -E "s/^/$(( $(wc -l $index | cut -d' ' -f1) + 1 )) /" >> $index \
274 echo -e '\nGist created' 277 && echo -e '\nGist created' \
278 || echo 'Fail to create gist'
279
275 _show_list $index | tail -1 280 _show_list $index | tail -1
276} 281}
277 282