diff options
author | typebrook <typebrook@gmail.com> | 2020-02-01 11:36:56 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-02-01 11:36:56 +0800 |
commit | 183fca611aa678b7af7ee447f8ab462323dbe7e4 (patch) | |
tree | 30486b62111fa46907ec24d8696aea2a74cbb09c | |
parent | fcb4152e634c8a3d2ff00bea39292e8212feff3a (diff) |
update
-rwxr-xr-x | scripts/gist | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/scripts/gist b/scripts/gist index d55516c..16102e8 100755 --- a/scripts/gist +++ b/scripts/gist | |||
@@ -133,15 +133,14 @@ _apply_config() { | |||
133 | fi | 133 | fi |
134 | 134 | ||
135 | source $CONFIG | 135 | source $CONFIG |
136 | |||
137 | [[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder | ||
138 | INDEX=$folder/index | ||
139 | AUTH_HEADER="Authorization: token $token" | ||
136 | } | 140 | } |
137 | 141 | ||
138 | _apply_config "$@" || exit 1 | 142 | _apply_config "$@" || exit 1 |
139 | 143 | ||
140 | AUTH_HEADER="Authorization: token $token" | ||
141 | |||
142 | [[ -z "$folder" ]] && folder=~/gist && mkdir -p $folder | ||
143 | INDEX=$folder/index | ||
144 | |||
145 | ## This function determines which http get tool the system has installed and returns an error if there isnt one | 144 | ## This function determines which http get tool the system has installed and returns an error if there isnt one |
146 | getConfiguredClient() | 145 | getConfiguredClient() |
147 | { | 146 | { |
@@ -291,21 +290,21 @@ _gist_id() { | |||
291 | } | 290 | } |
292 | 291 | ||
293 | _goto_gist() { | 292 | _goto_gist() { |
294 | _gist_id $1 | 293 | _gist_id $1 || return 1 |
295 | 294 | ||
296 | if [[ ! -d $folder/$GIST_ID ]]; then | 295 | if [[ ! -d $folder/$GIST_ID ]]; then |
297 | echo 'Cloning gist as repo...' | 296 | echo 'Cloning gist as repo...' |
298 | git clone git@github.com:$GIST_ID.git $folder/$GIST_ID | 297 | git clone git@github.com:$GIST_ID.git $folder/$GIST_ID |
299 | if [[ "$?" -ne 0 ]]; then | 298 | |
300 | echo 'Repo is cloned' > /dev/tty | 299 | if [[ $? -eq 0 ]]; then |
300 | echo 'Repo is cloned' > /dev/tty | ||
301 | else | 301 | else |
302 | echo 'Failed to clone the gist' > /dev/tty | 302 | echo 'Failed to clone the gist' > /dev/tty |
303 | return 1 | ||
303 | fi | 304 | fi |
304 | fi | 305 | fi |
305 | 306 | ||
306 | echo $folder/$GIST_ID | 307 | echo $folder/$GIST_ID |
307 | cd $folder/$GIST_ID && ls | ||
308 | #tig --all 2> /dev/null || true | ||
309 | } | 308 | } |
310 | 309 | ||
311 | _delete_gist() { | 310 | _delete_gist() { |
@@ -402,16 +401,17 @@ _create_gist() { | |||
402 | [[ -z "$description" ]] && read -p 'Type description: ' description < /dev/tty | 401 | [[ -z "$description" ]] && read -p 'Type description: ' description < /dev/tty |
403 | 402 | ||
404 | local index=$(( $(sed '/^s/ d' $INDEX | wc -l) +1 )) | 403 | local index=$(( $(sed '/^s/ d' $INDEX | wc -l) +1 )) |
405 | echo 'Creating a new gist' | 404 | echo 'Creating a new gist...' |
406 | for file in $files; do | 405 | for file in $files; do |
407 | echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"}," | 406 | echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"}," |
408 | done | tr -d '\n' | sed 's/^/{/; s/,$/}/' \ | 407 | done | tr -d '\n' | sed 's/^/{/; s/,$/}/' \ |
409 | | echo "{ \"public\": $public, \"files\": $(cat -), \"description\": \"$description\"}" \ | 408 | | echo "{ \"public\": $public, \"files\": $(cat -), \"description\": \"$description\"}" \ |
410 | | curl -s -H "$AUTH_HEADER" --data @- $GITHUB_API/gists \ | 409 | | curl -s -H "$AUTH_HEADER" --data @- $GITHUB_API/gists \ |
410 | | tee jojo \ | ||
411 | | sed '1 s/^/[/; $ s/$/]/' \ | 411 | | sed '1 s/^/[/; $ s/$/]/' \ |
412 | | _parse_response $index >> $INDEX | 412 | | _parse_response $index >> $INDEX |
413 | 413 | ||
414 | if [[ "$?" -ne 0 ]]; then | 414 | if [[ $? -eq 0 ]]; then |
415 | echo 'Gist is created' | 415 | echo 'Gist is created' |
416 | _show_list | tail -1 | 416 | _show_list | tail -1 |
417 | else | 417 | else |